function RemoveCheckToStringNodeVisitor::enterNode
Same name in other branches
- 10 core/lib/Drupal/Core/Template/RemoveCheckToStringNodeVisitor.php \Drupal\Core\Template\RemoveCheckToStringNodeVisitor::enterNode()
File
-
core/
lib/ Drupal/ Core/ Template/ RemoveCheckToStringNodeVisitor.php, line 25
Class
- RemoveCheckToStringNodeVisitor
- Defines a TwigNodeVisitor that replaces CheckToStringNodes.
Namespace
Drupal\Core\TemplateCode
public function enterNode(Node $node, Environment $env) : Node {
if ($node instanceof CheckToStringNode) {
// Replace CheckToStringNode with the faster equivalent, __toString is an
// allowed method so any checking of __toString on a per-object basis is
// performance overhead.
$new = new TwigSimpleCheckToStringNode($node->getNode('expr'));
// @todo https://www.drupal.org/project/drupal/issues/3488584 Update for
// Twig 4 as the spread attribute has been removed there.
if ($node->hasAttribute('spread')) {
$new->setAttribute('spread', $node->getAttribute('spread'));
}
return $new;
}
return $node;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.