Skip to content

Commit

Permalink
refac: filter use attribute instate of node
Browse files Browse the repository at this point in the history
  • Loading branch information
gimler committed Oct 23, 2024
1 parent 9b7e961 commit 604ecd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Twig/Visitor/DefaultApplyingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public function doEnterNode(Node $node, Environment $env): Node
return $node;
}

if (!($node instanceof FilterExpression && 'desc' === $node->getNode('filter')->getAttribute('value'))) {
if (!($node instanceof FilterExpression && 'desc' === $node->getAttribute('twig_callable')->getName())) {
return $node;
}

$transNode = $node->getNode('node');
while ($transNode instanceof FilterExpression
&& 'trans' !== $transNode->getNode('filter')->getAttribute('value')
&& 'transchoice' !== $transNode->getNode('filter')->getAttribute('value')) {
&& 'trans' !== $transNode->getAttribute('twig_callable')->getName()
&& 'transchoice' !== $transNode->getAttribute('twig_callable')->getName()) {
$transNode = $transNode->getNode('node');
}

Expand All @@ -69,7 +69,7 @@ public function doEnterNode(Node $node, Environment $env): Node
// if the |transchoice filter is used, delegate the call to the TranslationExtension
// so that we can catch a possible exception when the default translation has not yet
// been extracted
if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) {
if ('transchoice' === $transNode->getAttribute('twig_callable')->getName()) {
$transchoiceArguments = new ArrayExpression([], $transNode->getTemplateLine());
$transchoiceArguments->addElement($wrappingNode->getNode('node'));
$transchoiceArguments->addElement($defaultNode);
Expand Down
2 changes: 1 addition & 1 deletion Twig/Visitor/RemovingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setEnabled(bool $bool): void
protected function doEnterNode(Node $node, Environment $env): Node
{
if ($this->enabled && $node instanceof FilterExpression) {
$name = $node->getNode('filter')->getAttribute('value');
$name = $node->getAttribute('twig_callable')->getName();

if ('desc' === $name || 'meaning' === $name) {
return $this->enterNode($node->getNode('node'), $env);
Expand Down

0 comments on commit 604ecd2

Please sign in to comment.