Skip to content

Commit

Permalink
Merge pull request #591 from deguif/fix-twig-3.12-deprecations
Browse files Browse the repository at this point in the history
Fix deprecations triggered since twig 3.12.0
  • Loading branch information
goetas authored Sep 23, 2024
2 parents 90d26b3 + 3f7a03d commit d1f7e18
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Translation/Extractor/File/TwigFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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])) {
Expand Down
7 changes: 3 additions & 4 deletions Twig/DefaultApplyingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Twig/RemovingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d1f7e18

Please sign in to comment.