Skip to content
Snippets Groups Projects

Issue #3474822 by pdureau, sea2709, smustgrave, just_like_good_vibes: Normalize attributes values

Files
4
@@ -35,9 +35,12 @@ class ComponentElementAlter implements TrustedCallbackInterface {
public function alter(array $element): array {
$element = $this->normalizeSlots($element);
$component = $this->componentPluginManager->find($element['#component']);
$element = $this->processAttributesProp($element, $component);
$element = $this->processAttributesRenderProperty($element);
$element = $this->normalizeProps($element, $component);
// Attributes prop must never be empty, to avoid the processing of SDC's
// ComponentsTwigExtension::mergeAdditionalRenderContext() which is adding
// an Attribute PHP object before running the validator.
$element["#props"]["attributes"]['data-component-id'] = $component->getPluginId();
$element = $this->processAttributesRenderProperty($element);
return $element;
}
@@ -87,24 +90,6 @@ class ComponentElementAlter implements TrustedCallbackInterface {
return $element;
}
/**
* Process attributes prop.
*/
public function processAttributesProp(array $element, Component $component): array {
$element["#props"]["attributes"] = $element["#props"]["attributes"] ?? [];
// Attribute PHP objects are rendered as strings by SDC ComponentValidator,
// this is raising an error: "InvalidComponentException: String value
// found, but an object is required".
if (is_a($element["#props"]["attributes"], '\Drupal\Core\Template\Attribute')) {
$element["#props"]["attributes"] = $element["#props"]["attributes"]->toArray();
}
// Attributes prop must never be empty, to avoid the processing of SDC's
// ComponentsTwigExtension::mergeAdditionalRenderContext() which is adding
// an Attribute PHP object.
$element["#props"]["attributes"]['data-component-id'] = $component->getPluginId();
return $element;
}
/**
* Process #attributes render property.
*
Loading