function ComponentElement::preRenderComponent
Same name in this branch
- 11.x core/lib/Drupal/Core/Render/Element/ComponentElement.php \Drupal\Core\Render\Element\ComponentElement::preRenderComponent()
Same name in other branches
- 10 core/modules/sdc/src/Element/ComponentElement.php \Drupal\sdc\Element\ComponentElement::preRenderComponent()
- 10 core/lib/Drupal/Core/Render/Element/ComponentElement.php \Drupal\Core\Render\Element\ComponentElement::preRenderComponent()
Expands a sdc into an inline template with an attachment.
Parameters
array $element: The element to process. See main class documentation for properties.
Return value
array The form element.
Throws
\Drupal\sdc\Exception\InvalidComponentDataException
File
-
core/
modules/ sdc/ src/ Element/ ComponentElement.php, line 52
Class
- ComponentElement
- Provides a Single Directory Component render element.
Namespace
Drupal\sdc\ElementCode
public function preRenderComponent(array $element) : array {
$props = $element['#props'];
$props_alter_callbacks = $element['#propsAlter'];
// This callback can be used to prepare the context. For instance to replace
// tokens in the props.
$props = array_reduce($props_alter_callbacks, fn(array $carry, callable $callback) => $this->doTrustedCallback($callback, [
$carry,
], '%s is not trusted'), $props);
$inline_template = $this->generateComponentTemplate($element['#component'], $element['#slots'], $element['#slotsAlter'], $props);
$element['inline-template'] = [
'#type' => 'inline_template',
'#template' => $inline_template,
'#context' => $props,
];
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.