Problem/Motivation

\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray adds

        '#attributes' => ['class' => ['layout-builder-block']],

to all blocks rendered by Layout Builder, regardless of whether it is for the Layout Builder UI or for the end user.

Proposed resolution

Only add for the Layout Builder UI.
Consider adding it in a wrapping div instead of altering the block directly

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

johnwebdev’s picture

Do you want a specific test for this?

tim.plunkett’s picture

I think that's fine, as there are multiple other test cases that assert that it is present.
This perfectly addresses the first part of the proposed resolution.
Adding @lauriii who brought this up; he had more thoughts on the second half of the proposed resolution.

The last submitted patch, 2: 3042216-2--test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 2: 3042216-2.patch, failed testing. View results

johnwebdev’s picture

Status: Needs work » Needs review
FileSize
2.6 KB
803 bytes

Status: Needs review » Needs work

The last submitted patch, 7: 3042216-7.patch, failed testing. View results

johnwebdev’s picture

Status: Needs work » Needs review

Random fail

lauriii’s picture

Issue tags: +Needs followup

Any thoughts on moving this to Drupal\layout_builder\Element\LayoutBuilder::buildAdministrativeSection where we already do similar modifications to the render array?

Removing the class itself from outside of layout builder is valuable. We should open a follow-up for the idea of wrapping blocks with additional divs for attaching layout builder styles.

johnwebdev’s picture

#10 If we value to have the class added when the section is rendered in a preview mode, but outside Layout Builder UI we should keep it as-is. If we only need the class when rendered in the Layout Builder UI we could make that refactoring. But if the follow-up is to be done this needs to be moved anyway, so. I don't mind either way.

lauriii’s picture

We don't need the class in the preview mode since the preview mode is supposed to be rendered as close to the real page as possible. Reworked the patch so that the class is added in Drupal\layout_builder\Element\LayoutBuilder::buildAdministrativeSection.

johnwebdev’s picture

Status: Needs review » Reviewed & tested by the community

This looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed cf3d779799 to 8.8.x and cb1c980474 to 8.7.x. Thanks!

Backported to 8.7.x because layout builder is only stable in 8.7.0 so getting this done before then is helpful.

  • alexpott committed cf3d779 on 8.8.x
    Issue #3042216 by johndevman, lauriii, tim.plunkett: Only add .layout-...

  • alexpott committed cb1c980 on 8.7.x
    Issue #3042216 by johndevman, lauriii, tim.plunkett: Only add .layout-...

Status: Fixed » Closed (fixed)

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