function ComponentsTwigExtension::mergeAdditionalRenderContext
Same name in other branches
- 10 core/lib/Drupal/Core/Template/ComponentsTwigExtension.php \Drupal\Core\Template\ComponentsTwigExtension::mergeAdditionalRenderContext()
Calculates additional context for this template.
Parameters
\Drupal\Core\Plugin\Component $component: The component.
array $context: The context to update.
Return value
array The additional context to inject to component templates.
1 call to ComponentsTwigExtension::mergeAdditionalRenderContext()
- ComponentsTwigExtension::addAdditionalContext in core/
lib/ Drupal/ Core/ Template/ ComponentsTwigExtension.php - Appends additional context to the template based on the template id.
File
-
core/
lib/ Drupal/ Core/ Template/ ComponentsTwigExtension.php, line 78
Class
- ComponentsTwigExtension
- The twig extension so Drupal can recognize the new code.
Namespace
Drupal\Core\TemplateCode
protected function mergeAdditionalRenderContext(Component $component, array $context) : array {
$context['componentMetadata'] = $component->metadata
->normalize();
$component_attributes = [
'data-component-id' => $component->getPluginId(),
];
if (!isset($context['attributes'])) {
$context['attributes'] = new Attribute($component_attributes);
}
elseif ($context['attributes'] instanceof Attribute) {
$context['attributes']->merge(new Attribute($component_attributes));
}
return $context;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.