Problem/Motivation

From #3517033: Add a style utility API, some theme hook expect #item_attributes while #attributes is a standard for other renderable array.

The style API from the other ticket will default to #attributes, so better to ensure there is no special case.

Proposed resolution

- Make the special cases use #attributes
- Deprecate usage of #item_attributes

Remaining tasks

- Provide MR

User interface changes

None

Introduced terminology

None

API changes

New property of some them hooks.

Data model changes

None

Release notes snippet

CommentFileSizeAuthor
#8 search.png77.78 KBastonvictor

Issue fork drupal-3554447

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

grimreaper created an issue. See original summary.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Active » Needs review
nicxvan’s picture

This will need a change record at least.

While this is covered by bc policy https://www.drupal.org/about/core/policies/core-change-policies/frontend...
I think it could be disruptive so we should document it. One minor comment on the mr too.

smustgrave’s picture

Status: Needs review » Needs work

Definitely a CR. But the todo can it point to an issue too

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review

Hello,

Thanks for your reviews and feedbacks.

Draft CR created: https://www.drupal.org/node/3554585

I removed the todos in favor of proper deprecation warnings.

Should I create a follow-up issue for the deprecated code removal in Core 12?

astonvictor’s picture

StatusFileSize
new77.78 KB

tested locally. seems there are no other places to update. Attached screenshot after applying the patch.

let's wait for other reviewers to double check.

smustgrave’s picture

Status: Needs review » Needs work

can we get a deprecation test please

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review

Rebased and deprecation tests added.

Back to needs review.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Sorry small tweak can we bump to 11.4 think it’s too late for 11.3

Rest looks good though

grimreaper’s picture

Status: Needs work » Needs review

Sorry small tweak

Sorry, maybe I have not understood the expression, but I don't see any more code review comments.

The MR and the issue target 11.x, so it will be "automatically" for 11.4 now.

No need to specify it? Or did I miss something?

Thanks again for the review.

smustgrave’s picture

I mean the deprecations

grimreaper’s picture

Ok, MR updated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Feedback appears to be addressed

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

alexpott made their first commit to this issue’s fork.

alexpott’s picture

I've rebased the branch on top of main.

alexpott’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 85468ee47db to main and 54be7186870 to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 85468ee4 on main
    feat: #3554447 Use #attributes instead of #item_attributes
    
    By:...

  • alexpott committed 54be7186 on 11.x
    feat: #3554447 Use #attributes instead of #item_attributes
    
    By:...
alexpott’s picture

We can open a follow-up on main to remove the deprecation and #item_attributes.

grimreaper’s picture

Hello,

Thanks @alexpott for the merge!

I will do the follow up.
Should I also publish the CR?

grimreaper’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

berdir’s picture

For the record, this did break for us on 11.4 because we had a preprocess hook that added something to the attributes of an image. Looking at https://search.tresbien.tech/search?q=%23item_attributes%20-r%3Adrupal&n..., I think at least lazy.module definitely is also affected by this. I identified 3 different cases that alter item attributes like that in our distribution,

I know we can change render arrays like that, still a pretty subtle change that isn't obvious if you don't have explicit test coverage or tests you can run on 11.x that trigger deprecations. And I'm not sure if changing template parameters is a render array change for the dozens of examples there that use #theme image_formatter (some use their own templates with their own item_attributes), so making it a D12 deprecation is maybe a bit tricky.

BC is hard, just also defining attributes woudn't help, which one do you then use, how do you figure out if item_attributes or attributes was altered?

@grimreaper: I suspect your ui_styles project might also be affected? https://git.drupalcode.org/project/ui_styles/-/blob/8.x-1.x/src/StylePlu..., the bit about THEME_WITH_ITEM_ATTRIBUTES isn't going to work anymore like that when it's different on different core minor versions?

grimreaper’s picture

Thanks @berdir for the comment.

I forgot to update ui_styles because initially I expected #3517033: Add a style utility API to be merged "quickly" so handling the change directly in #3517009: POC: Core styles API.

I have created a follow up issue on ui_styles to handle that in the meantime, #3600682: [Core 11.4] Handle item_attributes removal.

mattsqd’s picture

Is there any chance we can have this behave more like this?

Something like this instead:

$variables['image']['#attributes'] = $variables['attributes'] ?? [];
if (isset($variables['item_attributes'])) {
    @trigger_error('Usage of #item_attributes is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use #attributes instead. See https://www.drupal.org/node/3554585', E_USER_DEPRECATED);
    $variables['image']['#attributes'] += $variables['item_attributes'];
}

Otherwise, anything set in $variables['attributes'] (like lazy = loading) will stop any modifications in $variables['item_attributes'] from applying.

grimreaper’s picture

Hi,

Good catch, please create a follow-up issue.

You can propose an MR if you want.

grimreaper’s picture