Drupal\Core\Template\Attribute doesn't support adding attributes with array syntax if attribute name not already initialised

Created on 17 January 2023, about 2 years ago

Problem/Motivation

The docs for Drupal\Core\Template\Attribute say

> add attributes using array syntax

and give this example:

 *  $attributes = new Attribute(array('id' => 'socks'));
 *  $attributes['class'] = array('black-cat', 'white-cat');
 *  $attributes['class'][] = 'black-white-cat';

However, if you try to use this as an array without initialising a property, like this:

 *  $attributes = new Attribute(array('id' => 'socks'));
 *  $attributes['class'][] = 'black-white-cat';

you get this error:

> Notice: Indirect modification of overloaded element of Drupal\Core\Template\Attribute has no effect

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Active

Version

10.1 โœจ

Component
Themeย  โ†’

Last updated about 24 hours ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

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