Plugin blocks cannot set their own attributes when put in the layout

Created on 28 August 2019, over 5 years ago
Updated 23 April 2023, over 1 year ago

Problem/Motivation

Normally, when creating block plugins, one can return an #attributes from the build() method. If that happens, the attributes are being added to the block's wrapper.

It looks like this logic is located here: https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/block/...

It doesn't work if the block has been put inside the layout, through the layout_builder. I consider it a bug, as anyone would expect the same behavior here, and it will surely break some custom plugin blocks relying on this feature.

Proposed resolution

Apply the same logic inside the BlockComponentRenderArray as it is in the BlockViewBuilder, to make #attributes work with the layout_builder.

Remaining tasks

Review the patch.

API changes

If anyone used #attributes to put attributes in the content of their block, instead of the block's wrapper, this change will probably break something for him. The weight of this issue is reduced by the fact, that this person would have to create this block plugin only to work in the layout builder, as outside of it, he would quickly notice that it doesn't work as expected.

πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
Layout builderΒ  β†’

Last updated 1 day ago

Created by

πŸ‡΅πŸ‡±Poland Luke_Nuke

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

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