function TwigTransTokenParser::parse
Same name in other branches
- 9 core/lib/Drupal/Core/Template/TwigTransTokenParser.php \Drupal\Core\Template\TwigTransTokenParser::parse()
- 8.9.x core/lib/Drupal/Core/Template/TwigTransTokenParser.php \Drupal\Core\Template\TwigTransTokenParser::parse()
- 11.x core/lib/Drupal/Core/Template/TwigTransTokenParser.php \Drupal\Core\Template\TwigTransTokenParser::parse()
File
-
core/
lib/ Drupal/ Core/ Template/ TwigTransTokenParser.php, line 30
Class
- TwigTransTokenParser
- A class that defines the Twig 'trans' token parser for Drupal.
Namespace
Drupal\Core\TemplateCode
public function parse(Token $token) {
$lineno = $token->getLine();
$stream = $this->parser
->getStream();
$body = NULL;
$options = NULL;
$count = NULL;
$plural = NULL;
if (!$stream->test(Token::BLOCK_END_TYPE) && $stream->test(Token::STRING_TYPE)) {
$body = $this->parser
->getExpressionParser()
->parseExpression();
}
if (!$stream->test(Token::BLOCK_END_TYPE) && $stream->test(Token::NAME_TYPE, 'with')) {
$stream->next();
$options = $this->parser
->getExpressionParser()
->parseExpression();
}
if (!$body) {
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser
->subparse([
$this,
'decideForFork',
]);
if ('plural' === $stream->next()
->getValue()) {
$count = $this->parser
->getExpressionParser()
->parseExpression();
$stream->expect(Token::BLOCK_END_TYPE);
$plural = $this->parser
->subparse([
$this,
'decideForEnd',
], TRUE);
}
}
$stream->expect(Token::BLOCK_END_TYPE);
$this->checkTransString($body, $lineno);
$node = new TwigNodeTrans($body, $plural, $count, $options, $lineno);
return $node;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.