21
21
use Twig \Node \Expression \Ternary \ConditionalTernary ;
22
22
use Twig \Node \Node ;
23
23
use Twig \Node \Nodes ;
24
- use Twig \NodeVisitor \AbstractNodeVisitor ;
24
+ use Twig \NodeVisitor \NodeVisitorInterface ;
25
25
use Twig \TwigFilter ;
26
26
27
27
/**
32
32
*
33
33
* @author Johannes M. Schmitt <[email protected] >
34
34
*/
35
- final class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
35
+ final class DefaultApplyingNodeVisitor implements NodeVisitorInterface
36
36
{
37
37
/**
38
38
* @var bool
@@ -50,14 +50,14 @@ public function doEnterNode(Node $node, Environment $env): Node
50
50
return $ node ;
51
51
}
52
52
53
- if (!($ node instanceof FilterExpression && 'desc ' === $ node ->getNode ( ' filter ' )->getAttribute ( ' value ' ))) {
53
+ if (!($ node instanceof FilterExpression && 'desc ' === $ node ->getAttribute ( ' twig_callable ' )->getName ( ))) {
54
54
return $ node ;
55
55
}
56
56
57
57
$ transNode = $ node ->getNode ('node ' );
58
58
while ($ transNode instanceof FilterExpression
59
- && 'trans ' !== $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )
60
- && 'transchoice ' !== $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )) {
59
+ && 'trans ' !== $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )
60
+ && 'transchoice ' !== $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )) {
61
61
$ transNode = $ transNode ->getNode ('node ' );
62
62
}
63
63
@@ -72,7 +72,7 @@ public function doEnterNode(Node $node, Environment $env): Node
72
72
// if the |transchoice filter is used, delegate the call to the TranslationExtension
73
73
// so that we can catch a possible exception when the default translation has not yet
74
74
// been extracted
75
- if ('transchoice ' === $ transNode ->getNode ( ' filter ' )->getAttribute ( ' value ' )) {
75
+ if ('transchoice ' === $ transNode ->getAttribute ( ' twig_callable ' )->getName ( )) {
76
76
$ transchoiceArguments = new ArrayExpression ([], $ transNode ->getTemplateLine ());
77
77
$ transchoiceArguments ->addElement ($ wrappingNode ->getNode ('node ' ));
78
78
$ transchoiceArguments ->addElement ($ defaultNode );
@@ -150,4 +150,14 @@ public function getPriority(): int
150
150
{
151
151
return -2 ;
152
152
}
153
+
154
+ public function enterNode (Node $ node , Environment $ env ): Node
155
+ {
156
+ return $ this ->doEnterNode ($ node , $ env );
157
+ }
158
+
159
+ public function leaveNode (Node $ node , Environment $ env ): ?Node
160
+ {
161
+ return $ this ->doLeaveNode ($ node , $ env );
162
+ }
153
163
}
0 commit comments