function ComponentElement::mergeElementAttributesToPropAttributes
Merge element attributes with props attributes.
#attributes property is an universal property of the Render API, used by many Drupal mechanisms from Core and Contrib, so we need to inject the values in template.
Parameters
array $element: The render element.
1 call to ComponentElement::mergeElementAttributesToPropAttributes()
- ComponentElement::preRenderComponent in core/
lib/ Drupal/ Core/ Render/ Element/ ComponentElement.php - Expands a component into an inline template with an attachment.
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ ComponentElement.php, line 164
Class
- ComponentElement
- Provides a Single-Directory Component render element.
Namespace
Drupal\Core\Render\ElementCode
private function mergeElementAttributesToPropAttributes(array &$element) : void {
if (!isset($element['#attributes'])) {
return;
}
// If attributes value is an array, convert it to an Attribute object as
// \Drupal\Core\Template\Atribute::merge() expects an Attribute object.
$element_attributes = is_array($element['#attributes']) ? new Attribute($element['#attributes']) : $element['#attributes'];
// Merge ['#attributes'] with the ['#props']['attributes']. So that #props
// attributes take precedence.
$element['#props']['attributes'] = empty($element['#props']['attributes']) ? $element_attributes : $element_attributes->merge($element['#props']['attributes']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.