Mercurial > hg > cmmr2012-drupal-site
diff core/lib/Drupal/Core/Template/TwigNodeTrans.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Template/TwigNodeTrans.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/lib/Drupal/Core/Template/TwigNodeTrans.php Thu May 09 15:34:47 2019 +0100 @@ -2,6 +2,8 @@ namespace Drupal\Core\Template; +use Twig\Node\CheckToStringNode; + /** * A class that defines the Twig 'trans' tag for Drupal. * @@ -18,12 +20,17 @@ * {@inheritdoc} */ public function __construct(\Twig_Node $body, \Twig_Node $plural = NULL, \Twig_Node_Expression $count = NULL, \Twig_Node_Expression $options = NULL, $lineno, $tag = NULL) { - parent::__construct([ - 'count' => $count, - 'body' => $body, - 'plural' => $plural, - 'options' => $options, - ], [], $lineno, $tag); + $nodes['body'] = $body; + if ($count !== NULL) { + $nodes['count'] = $count; + } + if ($plural !== NULL) { + $nodes['plural'] = $plural; + } + if ($options !== NULL) { + $nodes['options'] = $options; + } + parent::__construct($nodes, [], $lineno, $tag); } /** @@ -32,12 +39,10 @@ public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); - $options = $this->getNode('options'); - list($singular, $tokens) = $this->compileString($this->getNode('body')); $plural = NULL; - if (NULL !== $this->getNode('plural')) { + if ($this->hasNode('plural')) { list($plural, $pluralTokens) = $this->compileString($this->getNode('plural')); $tokens = array_merge($tokens, $pluralTokens); } @@ -67,8 +72,8 @@ $compiler->raw(')'); // Write any options passed. - if (!empty($options)) { - $compiler->raw(', ')->subcompile($options); + if ($this->hasNode('options')) { + $compiler->raw(', ')->subcompile($this->getNode('options')); } // Write function closure. @@ -113,6 +118,9 @@ $n = $n->getNode('node'); } + if ($n instanceof CheckToStringNode) { + $n = $n->getNode('expr'); + } $args = $n; // Support TwigExtension->renderVar() function in chain. @@ -134,6 +142,9 @@ } $args = $args->getNode('node'); } + if ($args instanceof CheckToStringNode) { + $args = $args->getNode('expr'); + } if ($args instanceof \Twig_Node_Expression_GetAttr) { $argName = []; // Reuse the incoming expression.