public function TwigTransTokenParser::parse

public TwigTransTokenParser::parse(\Twig_Token $token)

File

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

Class

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

Namespace

Drupal\Core\Template

Code

public function parse(\Twig_Token $token) {
  $lineno = $token->getLine();
  $stream = $this->parser->getStream();
  $body = NULL;
  $options = NULL;
  $count = NULL;
  $plural = NULL;

  if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test(\Twig_Token::STRING_TYPE)) {
    $body = $this->parser->getExpressionParser()->parseExpression();
  }
  if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test(\Twig_Token::NAME_TYPE, 'with')) {
    $stream->next();
    $options = $this->parser->getExpressionParser()->parseExpression();
  }
  if (!$body) {
    $stream->expect(\Twig_Token::BLOCK_END_TYPE);
    $body = $this->parser->subparse(array($this, 'decideForFork'));
    if ('plural' === $stream->next()->getValue()) {
      $count = $this->parser->getExpressionParser()->parseExpression();
      $stream->expect(\Twig_Token::BLOCK_END_TYPE);
      $plural = $this->parser->subparse(array($this, 'decideForEnd'), TRUE);
    }
  }

  $stream->expect(\Twig_Token::BLOCK_END_TYPE);

  $this->checkTransString($body, $lineno);

  $node = new TwigNodeTrans($body, $plural, $count, $options, $lineno, $this->getTag());

  return $node;
}

© 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::parse/8.1.x