2020use Twig \Node \Expression \FilterExpression ;
2121use Twig \Node \Expression \Ternary \ConditionalTernary ;
2222use Twig \Node \Node ;
23- use Twig \Node \Nodes ;
24- use Twig \NodeVisitor \AbstractNodeVisitor ;
25- use Twig \TwigFilter ;
23+ use Twig \NodeVisitor \NodeVisitorInterface ;
2624
2725/**
2826 * Applies the value of the "desc" filter if the "trans" filter has no
3230 *
3331 * @author Johannes M. Schmitt <[email protected] > 3432 */
35- final class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
33+ final class DefaultApplyingNodeVisitor implements NodeVisitorInterface
3634{
3735 /**
3836 * @var bool
@@ -50,14 +48,14 @@ public function doEnterNode(Node $node, Environment $env): Node
5048 return $ node ;
5149 }
5250
53- if (!($ node instanceof FilterExpression && 'desc ' === $ node ->getNode ( ' filter ' )->getAttribute ( ' value ' ))) {
51+ if (!($ node instanceof FilterExpression && 'desc ' === $ node ->getAttribute ( ' twig_callable ' )->getName ( ))) {
5452 return $ node ;
5553 }
5654
5755 $ transNode = $ node ->getNode ('node ' );
5856 while ($ transNode instanceof FilterExpression
59- && 'trans ' !== $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )
60- && 'transchoice ' !== $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )) {
57+ && 'trans ' !== $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )
58+ && 'transchoice ' !== $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )) {
6159 $ transNode = $ transNode ->getNode ('node ' );
6260 }
6361
@@ -72,7 +70,7 @@ public function doEnterNode(Node $node, Environment $env): Node
7270 // if the |transchoice filter is used, delegate the call to the TranslationExtension
7371 // so that we can catch a possible exception when the default translation has not yet
7472 // been extracted
75- if ('transchoice ' === $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )) {
73+ if ('transchoice ' === $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )) {
7674 $ transchoiceArguments = new ArrayExpression ([], $ transNode ->getTemplateLine ());
7775 $ transchoiceArguments ->addElement ($ wrappingNode ->getNode ('node ' ));
7876 $ transchoiceArguments ->addElement ($ defaultNode );
@@ -150,4 +148,15 @@ public function getPriority(): int
150148 {
151149 return -2 ;
152150 }
151+
152+ public function enterNode (Node $ node , Environment $ env ): Node
153+ {
154+ return $ this ->doEnterNode ($ node , $ env );
155+ }
156+
157+ public function leaveNode (Node $ node , Environment $ env ): ?Node
158+ {
159+ return $ this ->doLeaveNode ($ node , $ env );
160+ }
161+
153162}
0 commit comments