Updated: Comment #N
Problem/Motivation
In the 'Tools' block (which is enabled by default in the standard installation), there should be a contextual link 'Edit menu' but right now it just shows 'Configure Block'. Actually there's an 'Edit menu' link and we've tests for same also: MenuTest::testBlockContextualLinks
But somehow caching breaks stuff. See related issue: https://drupal.org/node/914382
How it appears now (no 'Edit menu'):
How it should appear (screenshot from 7.x):
Proposed resolution
Contextual links on menu blocks aren't working. The sad reason
for this is render caching (a fucking damn problem, seriously!).
if ($plugin->isCacheable()) {
$build[$entity_id]['#pre_render'][] = array($this, 'buildBlock');
// ...
}
else {
$build[$entity_id] = $this->buildBlock($build[$entity_id]);
}
$build[$key]['#block'] = $entity;
$this->moduleHandler()->alter(array('block_view', "block_view_$base_id"), $build[$entity_id], $plugin);
If the menu block is marked as cacheable (per default caching is enabled) $build[$entity_id]['content'] is
not filled, menu_block_view_system_menu_block_alter() is called
and does not do anything.
Solution: Probably move the #contextual_link handling onto the post_render level instead of the alter stuff
Remaining tasks
Decide how to fix it.
User interface changes
None (apart from the fact that contextual links will actually be visible).
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#19 | 2239833-19.patch | 2.05 KB | Wim Leers |
#14 | 2239833-14.patch | 2.04 KB | olli |
#14 | 2239833-fail.patch | 1.41 KB | olli |
#4 | menu_block_contextual_links-2239833-4.patch | 1000 bytes | Wim Leers |
Contextual-links-visible.png | 10.79 KB | cs_shadow |
Comments
Comment #1
cs_shadow CreditAttribution: cs_shadow commentedComment #2
cs_shadow CreditAttribution: cs_shadow commentedComment #3
dawehnerupdated the issue summary with my "research"
Comment #4
Wim LeersI must've introduced this regression in #2158003: Remove Block Cache API in favor of blocks returning #cache with cache tags.
I verified that is the only occurrence of this problem (by grepping for
#contextual_link
).Attached is a patch that fixes the regression and simplifies the code. The checking for
$build['content']
is completely unnecessary nowadays.Comment #5
dawehnerLet's be honest, this is major, compared to other broken stuff. Sadly we probably need a test which actually don't work
Comment #6
Wim Leers#5: Agreed with priority change, and with your assessment:
MenuTest::testBlockContextualLinks()
does test this:I don't understand why that didn't catch this problem.
Comment #7
dawehnerThis one was initially discovered while working on https://drupal.org/comment/8677783#comment-8677783 , so maybe this test failure would be fixed here. Sadly I don't have my tools avaiable right now to remember why it worked before.
Comment #8
Wim LeersWhat's still needed here?
Comment #9
moshe weitzman CreditAttribution: moshe weitzman commentedVerified that the code is considerably simpler and the bug is fixed.
Comment #10
catchIf this is exposed by https://drupal.org/comment/8677783#comment-8677783 I'm OK with committing this without explicit test coverage - we'll get it once the other issue is committed.
Committed/pushed to 8.x, thanks!
Comment #13
Wim LeersComment #14
olli CreditAttribution: olli commentedHere's a test.
Comment #16
dawehnerGood catch!
I want to understand that. How does that actually work? You first add block caching, then you access the page once. Isn't block caching not returning a value yet? I know the test fails otherwise, so I try to understand why.
Comment #17
olli CreditAttribution: olli commentedNot sure what you mean by that but the existing test adds the block with "Maximum age" set to
<no caching>
and we have two code paths (see IS) so the #pre_render path is not yet covered.Just curious, would it hurt/work to always run the #pre_render path?
Comment #18
olli CreditAttribution: olli commentedI think the original fix #4 was broken in 70bed33. Issue referenced in #10 went in but the Edit menu link is still missing.
Comment #19
Wim Leers#14 only needed a straight reroll against HEAD. It still fixes the problem, and adds the necessary regression test coverage. Here's that reroll.
Comment #20
catchSorry folk for issue history please open a new issue rather than re-opening the old one (unless it's for a revert), just adding tests here would have been a normal task, rather than major bug.
Comment #21
Wim LeersReupload and RTBC'd at #2379083: Regression (again): Menu contextual links no longer visible in menu blocks, when block caching is enabled.
Restoring status from before #14.