function ComponentNodeVisitor::leaveNode
Same name in this branch
- 10 core/lib/Drupal/Core/Template/ComponentNodeVisitor.php \Drupal\Core\Template\ComponentNodeVisitor::leaveNode()
Same name in other branches
- 11.x core/modules/sdc/src/Twig/ComponentNodeVisitor.php \Drupal\sdc\Twig\ComponentNodeVisitor::leaveNode()
- 11.x core/lib/Drupal/Core/Template/ComponentNodeVisitor.php \Drupal\Core\Template\ComponentNodeVisitor::leaveNode()
File
-
core/
modules/ sdc/ src/ Twig/ ComponentNodeVisitor.php, line 44
Class
- ComponentNodeVisitor
- Provides a ComponentNodeVisitor to change the generated parse-tree.
Namespace
Drupal\sdc\TwigCode
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('sdc_additional_context', new Node([
new ConstantExpression($component_id, $line),
]), $line), $line);
$print_nodes[] = new PrintNode(new FunctionExpression('sdc_validate_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.