Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TwigTransTokenParser.php

function TwigTransTokenParser::checkTransString

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

Parameters

\Twig\Node\Node $body: The expression to check.

int $lineno: The source line.

Throws

\Twig\Error\SyntaxError

1 call to TwigTransTokenParser::checkTransString()
TwigTransTokenParser::parse in core/lib/Drupal/Core/Template/TwigTransTokenParser.php
Parses a token and returns a node.

File

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

Class

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

Namespace

Drupal\Core\Template

Code

protected function checkTransString(Node $body, $lineno) {
    foreach ($body as $node) {
        if ($node instanceof TextNode || $node instanceof PrintNode && $node->getNode('expr') instanceof NameExpression || $node instanceof PrintNode && $node->getNode('expr') instanceof GetAttrExpression || $node instanceof PrintNode && $node->getNode('expr') instanceof FilterExpression) {
            continue;
        }
        throw new SyntaxError(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal