Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem/Motivation
When you currently enable a module, you'll notice that new local tasks are not visible. They only appear after clearing cache.
The problem was noticed in the field group module (#2848314: Add group button is not available at manage form display). But i notice that this is also the case for Field UI.
Steps to Reproduce:
- Go to the admin/modules
- Uninstall field ui
- Tasks are now gone on the 'Edit article content type' screen
- Install the module and refresh 'Edit article content type'. You'll notice that the tasks are not shown yet.
- Clear cache and refresh screen. The tabs are now correctly appearing.
Proposed resolution
Make sure that local tasks are also correctly rebuild when enabling modules.
Comment | File | Size | Author |
---|---|---|---|
#27 | 2861210.patch | 3.96 KB | borisson_ |
#21 | invalidate-tasks-2861210-21.patch | 3.94 KB | tetranz |
#20 | invalidate-tasks-2861210-20.patch | 1.6 KB | tetranz |
#19 | interdiff-2861210-14-19.txt | 4.23 KB | tetranz |
#19 | invalidate-tasks-2861210-19.patch | 1.9 KB | tetranz |
Comments
Comment #2
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedComment #3
cilefen CreditAttribution: cilefen commentedComment #4
jmmarquez CreditAttribution: jmmarquez at La Drupalera by Emergya for La Drupalera by Emergya commentedI am working on it!!
Comment #6
geek-merlinI expirienced this issue today.
@jmmarquez: any news?
Comment #7
tetranz CreditAttribution: tetranz at Third and Grove commentedHere's a patch for field_ui. The problem is caused by local task caching.
I'm not sure if this is the ideal way of doing it. It feels like it should be more generalized but I haven't quite figured out how to do that. This works with Seven, Adminimal and Bartik as admin themes.
Comment #8
tetranz CreditAttribution: tetranz at Third and Grove commentedComment #9
geek-merlinHmm, this is indeed an ad-hoc hack that only had a chance to be committed with a *very very very* good justification.
So we need some investigation: Why is this? What else might be stale in cache?
My gut feeling is, that after module install, all caches should be cleared. So why is this stale?
Also (additional info not in the IS): When i experienced that problem, it only appeared on one (i suppose the first i viewed) content type.
We need some debugging here.
Comment #10
tetranz CreditAttribution: tetranz at Third and Grove commentedYeah, I tend to agree. I'm not sure if it's worth spending more time on. I did this much because I had some spare time and treated it as a learning exercise.
It happens for me on all content types. i.e., Basic Page, Article and others. It also happens on other other entity types, e.g., content blocks.
As far as I know, cache is not cleared when you install a module either via the UI or drush. Whether or not cache should be cleared is probably a matter for debate. I notice that drupal console (unlike drush) does clear cache when it installs a module and the problem does not occur.
If you're testing, you have the problem in reverse to really see the issue. After you uninstall field_ui you need to clear cache to observe the tabs disappearing.
Hmm ... I notice that content translation seems to avoid this issue. It uses the same block of local tasks so I might dive into that to see if it yields any helpful information. Once content translation is setup and two languages defined, you can open the edit page for a node, then toggle the translate on and off for that content type admin/config/regional/content-language, refresh the node edit and the Translate tab appears and disappears as expected without cache clear.
Comment #11
tetranz CreditAttribution: tetranz at Third and Grove commentedI was missing the forest for the trees with that first attempt :)
Here's a much better general solution. The local task blocks need to depend on cache tag local_task. When a module is installed or uninstalled MenuRouterRebuildSubscriber::onRouterRebuild is called which rebuilds the menu links and local tasks.
Comment #13
tetranz CreditAttribution: tetranz at Third and Grove commentedSorry, I accidentally changed it to rtbc instead of review before. Looking at the failed test now.
Comment #14
tetranz CreditAttribution: tetranz at Third and Grove commentedComment #15
geek-merlinThis looks promising. Code is straightforward.
Comment #16
tetranz CreditAttribution: tetranz at Third and Grove commentedI had a further play with this and, not surprisingly I guess, it fixes similar issues involving other modules, not just field_ui.
A couple of things I tested were:
Adding and removing a menu tab to a view.
Installing and uninstalling the contact module and watching the Contact tab on user profiles.
It should help anything that implements hook_menu_local_tasks_alter and then invalidates the local_task cache tag.
Comment #17
geek-merlinOK code looks solid. That LocalTasksBlock should depend on cache tag local_task seems so obvious to me i dare set RTBC to get component maintainer's attention.
Comment #18
larowlanHi - can you upload two versions of the patch - a test-only patch and a test + fix patch.
The patch that only has tests in it should fail, so upload that one first.
This helps committers judge that the fix has test coverage.
Thanks!
Comment #19
tetranz CreditAttribution: tetranz at Third and Grove commentedThis should fail.
Comment #20
tetranz CreditAttribution: tetranz at Third and Grove commentedA few unnecessary use statements crept in at the top. This should fail.
Comment #21
tetranz CreditAttribution: tetranz at Third and Grove commentedThis should pass.
Comment #25
borisson_#18 is resolved in the #20/#21.
The actual fix is
+ $cacheability->addCacheTags(['local_task']);
in\Drupal\Core\Menu\Plugin\Block\LocalTasksBlock::build
, the rest are test-improvements / a new test.Comment #26
alexpottLet's get the cache tags from the plugin manager as this is where it comes from and what we need to stay in-sync with. So do
$cacheability->addCacheableDependency($this->localTaskManager);
instead.Comment #27
borisson_Comment #28
borisson_I'm pretty sure that #27 correctly resolves #26 and it was a really small fix. Since that was the only remark @alexpott had in #26 - I'm going to be bold and set it back to RTBC.
Comment #29
alexpottAdding review credit.
Comment #30
alexpottCommitted and pushed 3fe7057fdb to 8.7.x and f55cb49475 to 8.6.x. Thanks!
Comment #33
Wim LeersLate to the party but …
👌 ❤️
Comment #35
liquidcms CreditAttribution: liquidcms commentedTook a while trying to figure out why, when enabling field_group module, that Add Group button didn't show up on Manage form display. Turns out i needed to do a cr.
This is Drupal 8.7.8. Wondering why this is marked as closed (and sadly i can't modify status any more).