protected function Twig_TokenParser_For::checkLoopUsageCondition

1 call to Twig_TokenParser_For::checkLoopUsageCondition()
Twig_TokenParser_For::parse in drupal/core/vendor/twig/twig/lib/Twig/TokenParser/For.php
Parses a token and returns a node.

File

drupal/core/vendor/twig/twig/lib/Twig/TokenParser/For.php, line 87

Class

Twig_TokenParser_For
Loops over each item of a sequence.

Code

protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node) {
  if ($node instanceof Twig_Node_Expression_GetAttr && $node
    ->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node
    ->getNode('node')
    ->getAttribute('name')) {
    throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition', $node
      ->getLine(), $stream
      ->getFilename());
  }
  foreach ($node as $n) {
    if (!$n) {
      continue;
    }
    $this
      ->checkLoopUsageCondition($stream, $n);
  }
}