From 713c2623e5a35a52f56a918177de7c69e76f6908 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 22 Oct 2020 20:37:20 +0200 Subject: [PATCH] [TwigBridge] Remove "transchoice" from the code base --- .../TranslationDefaultDomainNodeVisitor.php | 17 +++++++---------- .../Twig/NodeVisitor/TranslationNodeVisitor.php | 10 ---------- .../Bridge/Twig/UndefinedCallableHandler.php | 1 - 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php index 55bc3ae9a8959..213365ed9f1ef 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php @@ -64,21 +64,18 @@ protected function doEnterNode(Node $node, Environment $env): Node return $node; } - if ($node instanceof FilterExpression && \in_array($node->getNode('filter')->getAttribute('value'), ['trans', 'transchoice'])) { + if ($node instanceof FilterExpression && 'trans' === $node->getNode('filter')->getAttribute('value')) { $arguments = $node->getNode('arguments'); - $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2; if ($this->isNamedArguments($arguments)) { - if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) { + if (!$arguments->hasNode('domain') && !$arguments->hasNode(1)) { $arguments->setNode('domain', $this->scope->get('domain')); } - } else { - if (!$arguments->hasNode($ind)) { - if (!$arguments->hasNode($ind - 1)) { - $arguments->setNode($ind - 1, new ArrayExpression([], $node->getTemplateLine())); - } - - $arguments->setNode($ind, $this->scope->get('domain')); + } elseif (!$arguments->hasNode(1)) { + if (!$arguments->hasNode(0)) { + $arguments->setNode(0, new ArrayExpression([], $node->getTemplateLine())); } + + $arguments->setNode(1, $this->scope->get('domain')); } } elseif ($node instanceof TransNode) { if (!$node->hasNode('domain')) { diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php index 89a15cd622c5d..3d5edb4ae1994 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php @@ -66,16 +66,6 @@ protected function doEnterNode(Node $node, Environment $env): Node $node->getNode('node')->getAttribute('value'), $this->getReadDomainFromArguments($node->getNode('arguments'), 1), ]; - } elseif ( - $node instanceof FilterExpression && - 'transchoice' === $node->getNode('filter')->getAttribute('value') && - $node->getNode('node') instanceof ConstantExpression - ) { - // extract constant nodes with a trans filter - $this->messages[] = [ - $node->getNode('node')->getAttribute('value'), - $this->getReadDomainFromArguments($node->getNode('arguments'), 2), - ]; } elseif ($node instanceof TransNode) { // extract trans nodes $this->messages[] = [ diff --git a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php index fa3049d3dd7c2..a058acb40af28 100644 --- a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php +++ b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php @@ -22,7 +22,6 @@ class UndefinedCallableHandler private static $filterComponents = [ 'humanize' => 'form', 'trans' => 'translation', - 'transchoice' => 'translation', 'yaml_encode' => 'yaml', 'yaml_dump' => 'yaml', ];