Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#12 | 3042216-12.patch | 5.64 KB | lauriii |
#7 | interdiff_3-7.txt | 803 bytes | johnwebdev |
#7 | 3042216-7.patch | 2.6 KB | johnwebdev |
#2 | 3042216-2.patch | 1.67 KB | johnwebdev |
#2 | 3042216-2--test-only.patch | 695 bytes | johnwebdev |
Comments
Comment #2
johnwebdev CreditAttribution: johnwebdev commentedDo you want a specific test for this?
Comment #4
tim.plunkettI 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.
Comment #7
johnwebdev CreditAttribution: johnwebdev commentedComment #9
johnwebdev CreditAttribution: johnwebdev commentedRandom fail
Comment #10
lauriiiAny 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.
Comment #11
johnwebdev CreditAttribution: johnwebdev commented#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.
Comment #12
lauriiiWe 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
.Comment #13
johnwebdev CreditAttribution: johnwebdev commentedThis looks good.
Comment #14
alexpottCommitted 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.