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