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
The Menu UI module implements several entity hooks for the Menu entity. But actually these hook implementations are clearing caches that need to be cleared even if the Menu UI module is not enabled.
The easiest way to see this is to install the minimal profile from a configuration export (as this does not have the Menu UI module installed):
- Install the minimal profile
- Make some configuration changes - for example the site name
- Use drush config-export to export your configuration to the sync directory
- drop your database and re-create an empty on with the same name
- Visit your site - you'll be taken to the installer and on the profile select screen you will be able to choose "Use existing configuration"
The menus will be broken.
Proposed resolution
Move the hook implementations into the Menu entity.
Remaining tasks
User interface changes
None
API changes
menu_cache_clear_all()
is deprecated in this issue as these are the only calls in core. The replacement is to call \Drupal::cache('menu')->invalidateAll();
directly.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#9 | 2983603-9.patch | 5.18 KB | alexpott |
#9 | 4-9-interdiff.txt | 1.75 KB | alexpott |
#4 | 2983603-4.patch | 4.35 KB | alexpott |
#4 | 2983603-4.test-only.patch | 984 bytes | alexpott |
Comments
Comment #2
alexpottDoing a cache rebuild fixes the issue.
Comment #4
alexpottHere's a test and a fix. Turns out menu_ui is doing things core should be.
Comment #6
bircherThe only reason I would leave this as "normal" priority is that cache clearing solves the symptoms. But this means menu_ui is needed for core tor work properly.
The patch just moves the code without restructuring the way things work. Ideally we would put the cache invalidation in the menu block plugin deriver but that can also be a followup.
Comment #7
catchGiven menu_cache_clear_all() is a one-liner, could we do the cache clear directly? It's only used in the three places which are deleted in this patch, meaning we could deprecate it in a follow-up (or here) too.
https://api.drupal.org/api/drupal/core%21includes%21menu.inc/function/me...
Comment #8
alexpottMakes sense these are the only usages. I'll update the issue summary and title to better reflection the problem and not the symptom.
Comment #9
alexpottThanks for the review @catch.
Comment #11
catchCommitted/pushed to 8.7.x and cherry-picked to 8.6.x. Thanks!
Comment #13
alexpottThe follow-up for derivative cache tags already exists - see #2633878: Finalize cacheability for plugins
Also created #2989461: Menu entity should clear plugin.manager.block even when block module not installed as a result of re-reviewing this issue.
Comment #15
quietone CreditAttribution: quietone at PreviousNext commentedpublish the change record