TwigNodeVisitor.php in Drupal 8
File
core/lib/Drupal/Core/Template/TwigNodeVisitor.php
View source
<?php
namespace Drupal\Core\Template;
class TwigNodeVisitor extends \Twig_BaseNodeVisitor {
protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) {
return $node;
}
protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) {
if ($node instanceof \Twig_Node_Print) {
if (!empty($this->skipRenderVarFunction)) {
unset($this->skipRenderVarFunction);
return $node;
}
$class = get_class($node);
$line = $node
->getTemplateLine();
return new $class(new \Twig_Node_Expression_Function('render_var', new \Twig_Node([
$node
->getNode('expr'),
]), $line), $line);
}
elseif ($node instanceof \Twig_Node_Expression_Filter) {
$name = $node
->getNode('filter')
->getAttribute('value');
if ('escape' == $name || 'e' == $name) {
$node
->getNode('filter')
->setAttribute('value', 'drupal_escape');
$this->skipRenderVarFunction = TRUE;
}
}
return $node;
}
public function getPriority() {
return 256;
}
}
Classes
Name |
Description |
TwigNodeVisitor |
Provides a Twig_NodeVisitor to change the generated parse-tree. |