protected function TwigTransTokenParser::checkTransString

protected TwigTransTokenParser::checkTransString(\Twig_Node $body, $lineno)

Ensure that any nodes that are parsed are only of allowed types.

Parameters

\Twig_Node $body: The expression to check.

int $lineno: The source line.

Throws

\Twig_Error_Syntax

File

core/lib/Drupal/Core/Template/TwigTransTokenParser.php, line 86

Class

TwigTransTokenParser
A class that defines the Twig 'trans' token parser for Drupal.

Namespace

Drupal\Core\Template

Code

protected function checkTransString(\Twig_Node $body, $lineno) {
  foreach ($body as $node) {
    if (
    $node instanceof \Twig_Node_Text
       || 
      ($node instanceof \Twig_Node_Print && $node->getNode('expr') instanceof \Twig_Node_Expression_Name)
       || 
      ($node instanceof \Twig_Node_Print && $node->getNode('expr') instanceof \Twig_Node_Expression_GetAttr)
       || 
      ($node instanceof \Twig_Node_Print && $node->getNode('expr') instanceof \Twig_Node_Expression_Filter)
      ) {
      continue;
    }
    throw new \Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Template!TwigTransTokenParser.php/function/TwigTransTokenParser::checkTransString/8.1.x