From 3f7a03d41370a790ff06f804b45c1f4695aca69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Mon, 2 Sep 2024 18:56:37 +0200 Subject: [PATCH] fix: fix deprecations triggered since twig 3.12.0 --- Translation/Extractor/File/TwigFileExtractor.php | 4 ++-- Twig/DefaultApplyingNodeVisitor.php | 7 +++---- Twig/RemovingNodeVisitor.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Translation/Extractor/File/TwigFileExtractor.php b/Translation/Extractor/File/TwigFileExtractor.php index d0c9af00..a34588e9 100644 --- a/Translation/Extractor/File/TwigFileExtractor.php +++ b/Translation/Extractor/File/TwigFileExtractor.php @@ -82,7 +82,7 @@ public function enterNode(Node $node, Environment $env): Node $message->addSource($this->fileSourceFactory->create($this->file, $node->getTemplateLine())); $this->catalogue->add($message); } elseif ($node instanceof FilterExpression) { - $name = $node->getNode('filter')->getAttribute('value'); + $name = $node->hasAttribute('name') ? $node->getAttribute('name') : $node->getNode('filter')->getAttribute('value'); if ('trans' === $name || 'transchoice' === $name) { $idNode = $node->getNode('node'); @@ -117,7 +117,7 @@ public function enterNode(Node $node, Environment $env): Node break; } - $name = $this->stack[$i]->getNode('filter')->getAttribute('value'); + $name = $this->stack[$i]->hasAttribute('name') ? $this->stack[$i]->getAttribute('name') : $this->stack[$i]->getNode('filter')->getAttribute('value'); if ($name === 'desc' || $name === 'meaning') { $arguments = iterator_to_array($this->stack[$i]->getNode('arguments')); if (! isset($arguments[0])) { diff --git a/Twig/DefaultApplyingNodeVisitor.php b/Twig/DefaultApplyingNodeVisitor.php index 881bf5c9..feddf431 100644 --- a/Twig/DefaultApplyingNodeVisitor.php +++ b/Twig/DefaultApplyingNodeVisitor.php @@ -59,13 +59,12 @@ public function enterNode(Node $node, Environment $env): Node if ( $node instanceof FilterExpression - && 'desc' === $node->getNode('filter')->getAttribute('value') + && 'desc' === ($node->hasAttribute('name') ? $node->getAttribute('name') : $node->getNode('filter')->getAttribute('value')) ) { $transNode = $node->getNode('node'); while ( $transNode instanceof FilterExpression - && 'trans' !== $transNode->getNode('filter')->getAttribute('value') - && 'transchoice' !== $transNode->getNode('filter')->getAttribute('value') + && !in_array($transNode->hasAttribute('name') ? $transNode->getAttribute('name') : $transNode->getNode('filter')->getAttribute('value'), ['trans', 'transchoice'], true) ) { $transNode = $transNode->getNode('node'); } @@ -83,7 +82,7 @@ public function enterNode(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->hasAttribute('name') ? $transNode->getAttribute('name') : $transNode->getNode('filter')->getAttribute('value'))) { $transchoiceArguments = new ArrayExpression([], $transNode->getTemplateLine()); $transchoiceArguments->addElement($wrappingNode->getNode('node')); $transchoiceArguments->addElement($defaultNode); diff --git a/Twig/RemovingNodeVisitor.php b/Twig/RemovingNodeVisitor.php index e9a11c68..5fd4ccd9 100644 --- a/Twig/RemovingNodeVisitor.php +++ b/Twig/RemovingNodeVisitor.php @@ -45,7 +45,7 @@ public function setEnabled($bool) public function enterNode(Node $node, Environment $env): Node { if ($this->enabled && $node instanceof FilterExpression) { - $name = $node->getNode('filter')->getAttribute('value'); + $name = $node->hasAttribute('name') ? $node->getAttribute('name') : $node->getNode('filter')->getAttribute('value'); if ('desc' === $name || 'meaning' === $name) { return $this->enterNode($node->getNode('node'), $env);