Convert attributes props to an Attribute object before Attribute::merge()

Created on 2 October 2025, 28 days ago

Problem/Motivation

Following Process #attributes render property Active , testing 11.3-dev with a few SDC themes and projects, I have met TypeError: Drupal\Core\Template\Attribute::merge(): Argument #1 ($collection) must be of type Drupal\Core\Template\Attribute, array given when there is already a SDC attribute prop with an array value.

Steps to reproduce

Any component renderable with an array as attributes prop:

[
  '#type' => 'component',
  '#component' => 'foo:bar',
  '#attributes' => [
    'foo' => 'bar',
  ],
  '#props' => [
    'attributes' => [
      'lorem' => 'ipsum',
    ]
  ]
]

Proposed resolution

ComponentElement::mergeElementAttributesToPropAttributes() is already aware about this issue:

// If attributes value is an array, convert it to an Attribute object as
// \Drupal\Core\Template\Attribute::merge() expects an Attribute object.

But it is converting the other value:
$element_attributes = is_array($element['#attributes']) ? new Attribute($element['#attributes']) : $element['#attributes'];

So, let's keep this conversion and add the conversion of the value which must fit \Drupal\Core\Template\Attribute::merge() expectations.

API changes

We don't break anything. But we may need a new test.

🐛 Bug report
Status

Active

Version

11.2 🔥

Component

single-directory components

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024