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

Breadcrumb

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

function SandboxNodeVisitor::enterNode

Overrides NodeVisitorInterface::enterNode

File

vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php, line 48

Class

SandboxNodeVisitor
@author Fabien Potencier <fabien@symfony.com>

Namespace

Twig\NodeVisitor

Code

public function enterNode(Node $node, Environment $env) : Node {
    if ($node instanceof ModuleNode) {
        $this->inAModule = true;
        $this->tags = [];
        $this->filters = [];
        $this->functions = [];
        return $node;
    }
    elseif ($this->inAModule) {
        // look for tags
        if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
            $this->tags[$node->getNodeTag()] = $node->getTemplateLine();
        }
        // look for filters
        if ($node instanceof FilterExpression && !isset($this->filters[$node->getAttribute('name')])) {
            $this->filters[$node->getAttribute('name')] = $node->getTemplateLine();
        }
        // look for functions
        if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) {
            $this->functions[$node->getAttribute('name')] = $node->getTemplateLine();
        }
        // the .. operator is equivalent to the range() function
        if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
            $this->functions['range'] = $node->getTemplateLine();
        }
        if ($node instanceof PrintNode) {
            $this->needsToStringWrap = true;
            $this->wrapNode($node, 'expr');
        }
        if ($node instanceof SetNode && !$node->getAttribute('capture')) {
            $this->needsToStringWrap = true;
        }
        // wrap outer nodes that can implicitly call __toString()
        if ($this->needsToStringWrap) {
            if ($node instanceof ConcatBinary) {
                $this->wrapNode($node, 'left');
                $this->wrapNode($node, 'right');
            }
            if ($node instanceof FilterExpression) {
                $this->wrapNode($node, 'node');
                $this->wrapArrayNode($node, 'arguments');
            }
            if ($node instanceof FunctionExpression) {
                $this->wrapArrayNode($node, 'arguments');
            }
        }
    }
    return $node;
}

API Navigation

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