Skip to content

Commit 58d2ca8

Browse files
committed
Remove Twig deprecations
1 parent 553ea2b commit 58d2ca8

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Diff for: Twig/Visitor/DefaultApplyingNodeVisitor.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
use Twig\Node\Expression\FilterExpression;
2121
use Twig\Node\Expression\Ternary\ConditionalTernary;
2222
use 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
@@ -32,7 +30,7 @@
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
}

Diff for: Twig/Visitor/RemovingNodeVisitor.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Twig\Environment;
1515
use Twig\Node\Expression\FilterExpression;
1616
use Twig\Node\Node;
17-
use Twig\NodeVisitor\AbstractNodeVisitor;
17+
use Twig\NodeVisitor\NodeVisitorInterface;
1818

1919
/**
2020
* Removes translation metadata filters from the AST.
2121
*
2222
* @author Johannes M. Schmitt <[email protected]>
2323
*/
24-
final class RemovingNodeVisitor extends AbstractNodeVisitor
24+
final class RemovingNodeVisitor implements NodeVisitorInterface
2525
{
2626
/**
2727
* @var bool
@@ -36,7 +36,7 @@ public function setEnabled(bool $bool): void
3636
protected function doEnterNode(Node $node, Environment $env): Node
3737
{
3838
if ($this->enabled && $node instanceof FilterExpression) {
39-
$name = $node->getNode('filter')->getAttribute('value');
39+
$name = $node->getAttribute('twig_callable')->getName();
4040

4141
if ('desc' === $name || 'meaning' === $name) {
4242
return $this->enterNode($node->getNode('node'), $env);
@@ -55,4 +55,15 @@ public function getPriority(): int
5555
{
5656
return -1;
5757
}
58+
59+
public function enterNode(Node $node, Environment $env): Node
60+
{
61+
return $this->doEnterNode($node, $env);
62+
}
63+
64+
public function leaveNode(Node $node, Environment $env): ?Node
65+
{
66+
return $this->doLeaveNode($node, $env);
67+
}
68+
5869
}

0 commit comments

Comments
 (0)