Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations triggered since twig 3.12.0 #591

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading