function TwigNodeVisitor::leaveNode

Implements Twig_NodeVisitorInterface::leaveNode().

We use this to inject a call to render -> twig_render() before anything is printed.

See also

twig_render

File

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

Class

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

Namespace

Drupal\Core\Template

Code

function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) {
  if ($node instanceof \Twig_Node_Print) {
    $this->isReference = FALSE;
    $class = get_class($node);
    return new $class(new \Twig_Node_Expression_Function('render', new \Twig_Node(array(
      $node
        ->getNode('expr'),
    )), $node
      ->getLine()), $node
      ->getLine());
  }
  if ($this->isReference) {
    if ($node instanceof \Twig_Node_Expression_Name) {
      $name = $node
        ->getAttribute('name');
      return new TwigNodeExpressionNameReference($name, $node
        ->getLine());
    }
    elseif ($node instanceof \Twig_Function_Function) {

      // Do something!
      $this->isReference = FALSE;
    }
  }
  return $node;
}