function ComponentNodeVisitor::leaveNode
Same name in this branch
- 11.x core/modules/sdc/src/Twig/ComponentNodeVisitor.php \Drupal\sdc\Twig\ComponentNodeVisitor::leaveNode()
Same name in other branches
- 10 core/modules/sdc/src/Twig/ComponentNodeVisitor.php \Drupal\sdc\Twig\ComponentNodeVisitor::leaveNode()
- 10 core/lib/Drupal/Core/Template/ComponentNodeVisitor.php \Drupal\Core\Template\ComponentNodeVisitor::leaveNode()
File
-
core/
lib/ Drupal/ Core/ Template/ ComponentNodeVisitor.php, line 42
Class
- ComponentNodeVisitor
- Provides a ComponentNodeVisitor to change the generated parse-tree.
Namespace
Drupal\Core\TemplateCode
public function leaveNode(Node $node, Environment $env) : ?Node {
if (!$node instanceof ModuleNode) {
return $node;
}
$component = $this->getComponent($node);
if (!$component) {
return $node;
}
$line = $node->getTemplateLine();
$print_nodes = [];
$component_id = $component->getPluginId();
$emoji = static::emojiForString($component_id);
if ($env->isDebug()) {
$print_nodes[] = new PrintNode(new ConstantExpression(sprintf('<!-- %s Component start: %s -->', $emoji, $component_id), $line), $line);
}
$print_nodes[] = new PrintNode(new FunctionExpression('attach_library', new Node([
new ConstantExpression($component->getLibraryName(), $line),
]), $line), $line);
$print_nodes[] = new PrintNode(new FunctionExpression('add_component_context', new Node([
new ConstantExpression($component_id, $line),
]), $line), $line);
$print_nodes[] = new PrintNode(new FunctionExpression('validate_component_props', new Node([
new ConstantExpression($component_id, $line),
]), $line), $line);
// Append the print nodes to the display_start node.
$node->setNode('display_start', new Node([
$node->getNode('display_start'),
$print_nodes,
]));
if ($env->isDebug()) {
// Append the closing comment to the display_end node.
$node->setNode('display_end', new Node([
new PrintNode(new ConstantExpression(sprintf('<!-- %s Component end: %s -->', $emoji, $component_id), $line), $line),
$node->getNode('display_end'),
]));
}
// Slots can be validated at compile time, we don't need to add nodes to
// execute functions during display with the actual data.
$this->validateSlots($component, $node->getNode('blocks'));
return $node;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.