Skip to content
Snippets Groups Projects
Commit 3d420a98 authored by Pierre Dureau's avatar Pierre Dureau
Browse files

Move data-component-id to TwigExtension::normalizeProps()

parent f289ae46
No related branches found
No related tags found
No related merge requests found
......@@ -36,11 +36,6 @@ class ComponentElementAlter implements TrustedCallbackInterface {
*/
public function alter(array $element): array {
$element = $this->normalizeSlots($element);
$component = $this->componentPluginManager->find($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;
}
......
......@@ -123,9 +123,12 @@ class TwigExtension extends AbstractExtension {
public function normalizeProps(array &$context, string $component_id): void {
$component = $this->componentManager->find($component_id);
$props = $component->metadata->schema['properties'] ?? [];
if (!isset($context['attributes'])) {
$context['attributes'] = [];
}
// 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.
// Attribute PHP object are casted as string by the validator and trigger
// '[attributes] String value found, but an object is required' error.
$context['attributes']['data-component-id'] = $component->getPluginId();
foreach ($context as $variable => $value) {
if (isset($component->metadata->slots[$variable])) {
$context[$variable] = SlotPropType::normalize($value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment