Problem/Motivation
When custom content blocks are placed at page by Layout Builder, there are no contextual links on this block. This is about viewing page, not editing. I dug deeper into the problem and noticed, that some of blocks still has contextual links, e.g. views-blocks and blocks with webforms. But custom content blocks (provided by core module 'block_content') hasn't any contextual links when rendered by layout builder. This also applies to some contrib modules, e.g. Config Pages blocks also has no contextual links with Layout Builder, but when I placed {{ title_suffix }} into config-pages.html.twig, contextual links appeared ar config pages blocks.
Also I found out, that contextual links appears only in those modules, that contains some additional or specific logic of contextual links generation.
Proposed resolution
Do something to attach contextual links to blocks, rendered by Layout Builder.
Remaining tasks
TBA
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #96 | 3020876-96.patch | 1.01 KB | petar.gnjidic |
| #87 | 3020876-87.patch | 3.7 KB | basvredeling |
| #84 | contextual_links_with_LB-3020876-84.patch | 3.77 KB | mr_scumbag |
| #76 | layoutbuilder-language-block.png | 43.97 KB | neclimdul |
| #76 | system-language-block.png | 45.36 KB | neclimdul |
Issue fork drupal-3020876
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
Comment #2
tim.plunkettBlocks placed through the Block UI have a 1:1 relationship with their storage, a single config entity solely dedicated to that block.
Blocks placed through Layout Builder are one small piece of a much larger puzzle, and in the case of overrides, are stored as a part of the node itself.
This means it must care for translations, revisions, moderation states, and other concurrent editing done by other users.
There are multiple issues working on solving all of those problems.
It will be very difficult indeed to allow the editing of these custom blocks directly from the view-side of things.
This is somewhat related to #2948828: Layout Builder's Field Blocks do not work with Quick Edit in that way.
Not saying it isn't possible, because we don't know yet. But as it stands, the current situation is by design in order to not exacerbate those scenarios above.
Comment #3
gun_dose commented@tim.plunkett, when I place usual reusable content block, this implies that this block is independent content item, that doesn't need to share it states with parent entity. We are talking about blocks, that are content entities, but not about block's config.
Also I spent a few hours with XDebug exploring this issue and I noticed, that '#contextual' element presents in block's render array almost all the way. And there are all parameters, that needed to render this link. But somewhere deep in renderer this element disappears. I can't understand, why.
Comment #5
tim.plunkettComment #6
bgronek commentedI respectfully propose that this be labelled as a bug as opposed to a feature request as contextual links are a part of Drupal 8 which is expected to work for rendered blocks.
Comment #7
tim.plunkettFor reusable blocks, yes. I'm not sure about inline blocks though just yet.
Comment #8
thursday_bw commentedI have just started working with layout builder in drupal 8.7 today.
I have a content type, whose teaser view mode is rendered via layout builder.
I then have that teaser display by a view, in a block. And the view's block is then placed on yet another layout for a specific node.
When I view that specific node, I expected to see contextual links for my original content type's teaser.. I get links to the view but not to the node that is rendered in that view's block.. Appears to be the same or at least very similar issue to that described here.
Comment #9
meecect commentedI have seen similar behavior. I think it goes beyond just title_suffix, as #2 suggested.
For example, even in bartik, when placing a menu block, you don't even get a proper 'id' on the block header. You get something like this:
<h2 id="-menu">My block title</h2>This is because there is no 'attributes' value delivered to the block twig template, so it doesn't have access to things like the block id.
Compare that to another block that I placed via the Block UI in the Bartik sidebar:
<h2 id="block-bartik-tools-menu">Tools</h2>Of course without the id attribute, it makes styling harder, but more importantly, the moment you place two menu blocks you will have html elements with duplicate ID's.
Comment #10
sakiland commentedI think I've found the solution.
The issue is on building block in file core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php
so, I've added following code after it, and works for me
Please check the patch.
Comment #11
sakiland commentedHere's fixed patch with corrected relative file paths
Comment #12
sakiland commentedFixed patch.
Comment #13
acbramley commentedThrough manual testing I can confirm #12 fixes the issue with displaying contextual links for block content entities added via layout builder. We do need automated tests though :)
Comment #14
acbramley commentedI've just encountered a bug through using this, we shouldn't be rendering contextual links for inline blocks. This lead to me editing an inline block via the normal UI (which sounds like it shouldn't be allowed), leading to some weird behaviour.
Comment #15
chris burge commentedRe #14, the ability to edit inline blocks could be useful, given the issues in #2 are addressed. Can you document the "weird behaviour"?
Comment #16
acbramley commented@Chris Burge they are editable via layout builder using the "Configure" link when on the layout page. I've documented why I don't think they should be editable via the UI in #3075308: Inline blocks shouldn't be editable via the normal block content UI
Comment #17
chris burge commentedI can confirm that #12 causes contextual links to be rendered for blocks (both re-usable and inline).
The ability to edit inline blocks via a contextual link would be a UX improvement, so long as the issues described in #2 are addressed. (See #3075308-3: Inline blocks shouldn't be editable via the normal block content UI.)
Here are steps to reproduce the "weird behavior" identified in #14:
Comment #18
xjmIf I'm reading this right this is a major bug.
Comment #19
drclaw commentedWhile we're figuring out what to do with inline blocks, here's a patch that will just skip any inline blocks contextual links. Same patch as #12, just with the extra check for any blocks with the inline_block base plugin id.
Comment #21
sam152 commentedI added my thoughts on allowing inline blocks to be edited outside of LB to: #3075308: Inline blocks shouldn't be editable via the normal block content UI. In summary, I think it's really bad and we should fix that bug as soon as possible.
I added a proposal in there for how contextual links for inline blocks could work:
This issue could be repurposed or closed in favour of adding this as a new feature and the issue linked above could address the bug.
Comment #22
sam152 commentedFWIW, I've also tentatively closed #3052042: If an inline block has been edited outside of layout builder it can't be edited in layout builder, so fixing this issue without explicitly excluding inline blocks would expose a lot more users to a major bug.
Comment #23
iamdroid commentedReroll of #19 for 8.8.0-rc1.
Comment #24
batkorUpdate patch.
Add contextual links only block_content
Comment #25
batkorOh, sorry bad patch in #24 comment
Comment #26
sivaji_ganesh_jojodae commentedComment #27
sivaji_ganesh_jojodae commentedComment #28
mortona2k commentedThis patch works for some views blocks.
I had issues with the view contextual links being hidden by one from the listed items.
Comment #29
tim.plunkettThis reminds me of the patch in #3077734: Plugin blocks cannot set their own attributes when put in the layout.
Maybe that one (which only handles #attributes, but in the same exact way) should be combined with this?
Also I'm not sure that this needs to be special cased to block_content. If it should, then it should be moved to a new subscriber in that module.
Comment #30
tim.plunkettComment #32
i-trokhanenkoAdded
'#contextual_links'directly to$buildarray. Works well for me. Please test.Comment #34
bunty badgujar commentedI'm Working on it.
Comment #35
grayle commentedOne thing I've noticed with the last patch is that it adds contextual links for non-resuable, inline LB blocks as well (for Layout Overrides, haven't checked 'default' Layouts). Which I believe is an issue, as if you edit those separately it breaks the link to the layout.
Comment #36
alex_optimComment #37
alex_optimComment #38
alex_optimFixed tests.
Comment #39
alex_optimComment #40
jddh commented+1 for this crucial feature add. Content editors should be able to quickly edit the parts of a Layout Builder layout without having to hunt things down in the Custom Block Library. This feature would sync up expected behaviour from back in the Panels days.
Comment #42
mrweiner commentedUnrelated to the patch, but I came across this issue while trying to figure out why my Contextual Links were missing on the layout tab for a block type with a template override. The reason was that I wasn't rendering the
{{ title_suffix }}, which apparently contains the contextual menu. Just in case anybody else lands here via search for the same reason.Comment #43
tom.moffett commented@mrweiner I thankfully stumbled upon your post while researching my several issues with getting Paragraphs to play nice with Layout Builder and vice versa. There were some other things I also needed to resolve, but your post has saved me from going into a dark hole of debugging on this particular issue, so I was able to use my work day to get actual things accomplished. Thanks for posting your findings!
Comment #44
maskedjellybeanI bet we've all been there. To think how much time we've collectively wasted before realizing `{{ title_suffix }}` actually means contextual links. Oh Drupal.
Comment #45
batkor#38 worked for me
Drupal 9.0.8
Comment #46
batkorComment #47
tim.plunkettI think this needs a test involving reusable content blocks (as per this issue title) that proves the bug is fixed.
Comment #48
taiger commented#38 worked for me
Drupal 8.9.11
Comment #49
camilo 1990 commentedToday I update to 8.9.13 and it stopped working.
Comment #50
matt_paz commented#38 was working for me, but one thing I noticed was that when some blocks (maybe only those using paragraphs -- I didn't dig deeply yet) edited through the contextual links while viewing were loosing some attributes resulting in the block being unable to be changed in layout builder. I didn't dig into this deeply, but I'd presume it had something to do with revision status not being updated in layout builder or something. This is very possibly unrelated to this patch directly (and possibly more related to #3047022 (or the like), but I thought I'd add a note about observations so far (in case others find this issue and encounter something similar), but removing this patch seems to reduce the risk of other issues. Sorry for the noise, but I thought it _might_ be helpful to others as they work through a range of lb-related issues.
Comment #51
bunty badgujar commentedComment #52
kthull#38 applied cleanly and did the job for me with standard reusable core blocks and D9.1.4
Comment #54
tim.plunkettThe MR branch is empty.
#29 is still unaddressed.
Comment #55
ivnish#38 worked for me
Drupal 9.1.5
Comment #58
mohit_aghera commented@tim.plunkett
I've merged patches from both issues:
https://www.drupal.org/project/drupal/issues/3020876#comment-13836979
https://www.drupal.org/project/drupal/issues/3077734#comment-13549037
Regarding #29, there is already one change in
core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.phpfile in PR #501Can you please check if this is what you were expecting?
I've removed the Needs test tag, as the other PR already had a few test cases with the block.
Comment #59
mohit_aghera commentedComment #60
longwaveI came here via https://www.drupal.org/project/layout_builder_ibqe
To me #29 is addressed but there is a minor nit in that 'content' is set in the array then overwritten a few lines later.
Comment #62
chris.smith commentedJust want to ad that #38 worked for me. Not sure what work is remaining, but it does what I need. Thx
Comment #63
jeffc518 commentedOh man, a HUGE thank you to @mrweiner for mentioning the
I couldn't figure out why the contextual link to configure / remove blocks was not appearing in Layout Builder, so I went hunting for patches. I rarely use the block titles so I didn't even think twice about removing these. I put them back in and voila.
FYI for anyone TLDR;
Comment #65
pfrenssenComment #66
dimilias commentedLet's draw some attention. RTBC +1. Works fine for us. :)
Comment #67
alexpottCommitted and pushed 6d04e573e3 to 9.3.x and bbf39c4341 to 9.2.x. Thanks!
Comment #70
batkorNice!
Comment #72
dave reidThis core change has caused a major regression in our Drupal site which uses custom blocks to add classes to our components in the block's $build['#attributes'] array.
This is an example of the build render array that we are using in our block's build() method:
Before, these #attributes would be passed to our Twig template for this component, but now they have gone missing, and are added to the wrapping block
<div>instead, which broke all of our output.I also don't see a change notice about this.
Comment #73
dave reidComment #74
dave reidBlockPluginInterface::build() mentions nothing about $build['#attributes'] being moved, or being owned by the wrapping block markup.
Which now seems at odds with the new comment added here:
Comment #75
dave reidCore blocks that are affected by this change:
\Drupal\language\Plugin\Block\LanguageBlock::build
Comment #76
neclimdulThat does sound like a pretty big regression if you where relying on it. After spending some time comparing the effects of the patch on the language block the effect seems like exactly what the fix was trying to do. The issue is about fixing contextual links but the reason contextual links weren't working was that blocks where rendering different if they where in LB versus placed on the page normally.
Language block in a theme region:

And the same block placed in a layout prior to the patch highlighting how the class moved.

You can see how the class moving aligns it with the "standard" rendering which would fix a class of bugs like contextual links but also how disruptive that move would be to heavy layout builder users relying on that class placement like Dave.
Comment #77
tim.plunkettFrom a discussion in Slack:
This is a tricky situation. Because from 8.7 to 9.1, block.module placed blocks worked one way and LB placed blocks worked another. and now in 9.2+, they work the same way. But that switch broke the expectations of any block that was only ever intended to work in LB...
LanguageBlock is and has been broken in the way @Dave Reid observed when placed in the Block UI.
I'd propose a follow-up for fixing LanguageBlock, and perhaps adding docs to BPI::build() at the same time.
This issue should have a CR to explain the break and what to do about it (nesting your render array one level down sidesteps this).
Comment #78
xmacinfoDo we need to create a new issue to fix the regression? Or do we only need to document the change in a Change Records? Any core blocks affected that need a fix?
Comment #79
jsacksick commentedThis has been driving me crazy :). After some digging it turns out this is what's causing the Commerce core tests to fail on Drupal core 9.2 (Created #3247884: Fix the 9.2 test failures today).
Commerce has tests coverage for its Layout builder integration, and tests have been failing since this got committed, due to the markup changing between ajax requests (i.e the "block-field-block-..." wrapper disappearing as well as the content div around the field after a different product variation attributed is selected on add to cart.
This is actually a Commerce release blocker, but looks like I may have to comment out the code that's failing in tests until this gets resolved.
Comment #80
jsacksick commentedFor reference, when landing on the product page, a div with the following class exists on the page:
Then, the following fails:
The same div no longer exists after the ajax refresh.
Comment #82
yom commentedHi, to illustrate what jsacksick said, here is a concrete example of the problem encountered on Commerce core, this behavior can not remain as is in a professional perspective...
https://www.drupal.org/project/commerce/issues/3253323
Comment #84
mr_scumbagUpdating the patch for Drupal 9.4
Comment #86
basvredelingReroll of patch #84 for Drupal 9.5.2
Comment #87
basvredelingI ran the previous patch diff against the wrong dir. Here's the correct one.
Comment #94
smustgrave commentedClosed #3077734: Plugin blocks cannot set their own attributes when put in the layout as a duplicate
Comment #96
petar.gnjidic commentedThis patch works with core 9.5.x and 10.2.x.
Comment #97
ivanilic commented@petar.gnjidic
this patch from #96 only works if you don't have revision. Moment you check revision checkbox on the block and save it - contextual links are gone again.
Could you try to reproduce it?
Thanks