class TestNodeVisitor

Same name in this branch
  1. 11.x core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php \Drupal\sdc_other_node_visitor\Twig\NodeVisitor\TestNodeVisitor
Same name and namespace in other branches
  1. 10 core/modules/sdc/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php \Drupal\sdc_other_node_visitor\Twig\NodeVisitor\TestNodeVisitor
  2. 10 core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php \Drupal\sdc_other_node_visitor\Twig\NodeVisitor\TestNodeVisitor

A node visitor that adds nodes to the Twig template.

Most of this code is copied from Twig\Profiler\NodeVisitor\ProfilerNodeVisitor.

Hierarchy

  • class \Drupal\sdc_other_node_visitor\Twig\NodeVisitor\TestNodeVisitor extends \Twig\NodeVisitor\NodeVisitorInterface

Expanded class hierarchy of TestNodeVisitor

2 files declare their use of TestNodeVisitor
TestProfilerExtension.php in core/modules/sdc/tests/modules/sdc_other_node_visitor/src/Twig/Extension/TestProfilerExtension.php
TestProfilerExtension.php in core/modules/system/tests/modules/sdc_other_node_visitor/src/Twig/Extension/TestProfilerExtension.php

File

core/modules/sdc/tests/modules/sdc_other_node_visitor/src/Twig/NodeVisitor/TestNodeVisitor.php, line 18

Namespace

Drupal\sdc_other_node_visitor\Twig\NodeVisitor
View source
final class TestNodeVisitor implements NodeVisitorInterface {
    private string $extensionName;
    private string $varName;
    
    /**
     * TestNodeVisitor constructor.
     *
     * @param string $extensionName
     *   The name of the extension.
     */
    public function __construct(string $extensionName) {
        $this->extensionName = $extensionName;
        $this->varName = sprintf('__internal_%s', hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName));
    }
    
    /**
     * {@inheritdoc}
     */
    public function enterNode(Node $node, Environment $env) : Node {
        return $node;
    }
    
    /**
     * {@inheritdoc}
     */
    public function leaveNode(Node $node, Environment $env) : ?Node {
        if ($node instanceof ModuleNode) {
            $node->setNode('display_start', new Node([
                new EnterProfileNode($this->extensionName, $this->varName),
                $node->getNode('display_start'),
            ]));
            $node->setNode('display_end', new Node([
                new LeaveProfileNode($this->varName),
                $node->getNode('display_end'),
            ]));
        }
        return $node;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPriority() : int {
        return 0;
    }

}

Members

Title Sort descending Modifiers Object type Summary
TestNodeVisitor::$extensionName private property
TestNodeVisitor::$varName private property
TestNodeVisitor::enterNode public function
TestNodeVisitor::getPriority public function
TestNodeVisitor::leaveNode public function
TestNodeVisitor::__construct public function TestNodeVisitor constructor.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.