function TwigExtension::getNodeVisitors

Same name in this branch
  1. 10 core/modules/sdc/src/Twig/TwigExtension.php \Drupal\sdc\Twig\TwigExtension::getNodeVisitors()
Same name in other branches
  1. 9 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getNodeVisitors()
  2. 8.9.x core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getNodeVisitors()
  3. 11.x core/modules/sdc/src/Twig/TwigExtension.php \Drupal\sdc\Twig\TwigExtension::getNodeVisitors()
  4. 11.x core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getNodeVisitors()

File

core/lib/Drupal/Core/Template/TwigExtension.php, line 158

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

public function getNodeVisitors() {
    // The node visitor is needed to wrap all variables with
    // render_var -> TwigExtension->renderVar() function.
    $visitors = [
        new TwigNodeVisitor(),
        new TwigNodeVisitorCheckDeprecations(),
    ];
    if (\in_array('__toString', TwigSandboxPolicy::getMethodsAllowedOnAllObjects(), TRUE)) {
        // When __toString is an allowed method, there is no point in running
        // \Twig\Extension\SandboxExtension::ensureToStringAllowed, so we add a
        // node visitor to remove any CheckToStringNode nodes added by the
        // sandbox extension.
        $visitors[] = new RemoveCheckToStringNodeVisitor();
    }
    return $visitors;
}

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