function TwigNodeVisitor::enterNode

Implements Twig_NodeVisitorInterface::enterNode().

File

drupal/core/lib/Drupal/Core/Template/TwigNodeVisitor.php, line 33
Definition of Drupal\Core\Template\TwigNodeVisitor.

Class

TwigNodeVisitor
Provides a Twig_NodeVisitor to change the generated parse-tree.

Namespace

Drupal\Core\Template

Code

function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
  if ($node instanceof \Twig_Node_Expression_Function) {
    $name = $node
      ->getAttribute('name');
    $func = $env
      ->getFunction($name);

    // Optimization: Do not support nested functions.
    if ($this->isReference && $func instanceof \Twig_Function_Function) {
      $this->isReference = FALSE;
    }
    if ($func instanceof TwigReferenceFunction) {

      // We need to create a TwigReference
      $this->isReference = TRUE;
    }
  }
  if ($node instanceof \Twig_Node_Print) {

    // Our injected render needs arguments passed by reference -- in case of render array
    $this->isReference = TRUE;
  }
  return $node;
}