Problem/Motivation
The menu API doesn't require one to use Menu config entities. Yet the rendering of menus is tied to that.
Proposed resolution
Fix this by using menu cache tags that aren't tied to Menu config entities, and have Menu config entities use those non-coupled cache tags too.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Beta phase evaluation
| Issue category | Task because menus as a concept should not be tied to Menu config objects. That prevents developers from maintaining their own menu trees outside of Menu config objects. |
|---|---|
| Issue priority | Normal. |
| Prioritized changes | The main goal of this issue is API correctness/completeness. |
| Disruption | Zero disruption. |
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | use_menu_menu_name-2488918-39.patch | 10.11 KB | Anonymous (not verified) |
| #37 | use_menu_menu_name-2488918-37.patch | 9.67 KB | Anonymous (not verified) |
| #31 | interdiff.txt | 639 bytes | lauriii |
| #31 | use_menu_menu_name-2488918-31.patch | 10.5 KB | lauriii |
| #25 | interdiff.txt | 778 bytes | lauriii |
Issue fork drupal-2488918
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 #1
wim leersComment #5
dawehnerShould we also add config: as well, just in case someone needs it.
Comment #6
wim leers#5: We could do that, but I don't understand why. They should just be using
Menu::getCacheTags(), which would automatically be correct.More importantly, the failure that is showing up… I don't think I can actually fix that. Config entities in the end are merely config objects. It's the
\Drupal\Core\Config\Config::save()method that does the actual cache tag invalidation… and I don't see how we can make the config objects associated with Menu config entities aware of the custom cache tags we are specifying. Config is special like that.So the failure we are seeing is a legitimate failure, because the
menu:<menu name>cache tag is not being invalidated.Ideas?
Comment #7
fabianx commentedShould Config::save() not check if the entity it is saving implements CacheableDependencyInterface and then merge those cacheTags in, too?
Comment #8
wim leersNo,
Config::save()does not have access to the config entity.Comment #9
fabianx commentedSpoke with @alexpott in IRC:
There are 2 ways:
- Use the normal entity hooks and implement them in menu module, to invalidate tags on save
- Do it like views or VocabularyStorage and subclass ConfigEntityStorage and override the save() / resetCache() methods to do our own invalidation
After thinking about it, its still worth it to have clearer semantics here as this cache tags will be output by almost every Drupal 8 site online, so it would be good to have less coupling ...
CNW for the above changes, needs a beta evaluation.
Comment #10
wim leersDone.
Comment #11
wim leersNow with 100% more patch.
Comment #14
wim leersComment #15
berdirAFAIK, it's officially still not allowed to mix @inheritdoc and additional docblock comments. I'd recommend to make this an inline comment to avoid discussions about this...
Same.
Comment #16
fabianx commentedTests pass, the llama is happy, solution looks good, RTBC!
Comment #17
dawehnerSeems fine
Comment #18
fabianx commentedCNW per #16, cross-post (also to avoid commit conflicts with the more important cache menu links issue).
Comment #19
wim leers#1805054: Cache localized, access filtered, URL resolved, and rendered menu trees landed, this can now be rerolled. With the trivial doc fixes in #16, this will be RTBC again.
Comment #20
berdirDid that, since it's my fault that it's needed ;)
Also not sure why the cache tag invalidation happens in MenuStorage. Trying something....
Comment #21
berdirClearing the cache tag in the method that we also use everywhere else seems like a much more logical thing to do? :)
Comment #22
fabianx commentedberdir++ - We only used the custom storage, because of #9(I spoke with alexpott and he saw no other ways), but this way is obviously better.
RTBC!
Comment #23
wim leersBerdir++
RTBC++
Comment #24
alexpottI think we also need to implement
invalidateTagsOnDelete. Also how about not calling the parent to save a query and couple the classes less?Comment #25
lauriiiComment #28
wim leersThe if-statement is unnecessary/wrong.
Comment #29
fabianx commentedYeah, that won't fly ...
Comment #31
lauriiiI guess I was _little_ tired last night. Fixing my own mess
Comment #32
alexpottIt super sub-optimal do have multiple calls to
Cache::invalidateTags(). Each call is a query I think. So we can merge the arrays of tags first and do a single call toCache::invalidateTags()for both save and delete. Plus the green patch in #21 shows we're missing test coverage.Comment #33
lauriiiJust tagging first
Comment #34
RavindraSingh commentedComment #35
wim leers#32: I agree in principle, but the only way to merge the tags first in this case, is by breaking through the abstraction and duplicating the logic of the parent methods. So I think the solution in this patch is actually fine. Especially because it is for
Menuentities (not menu links!), which change rarely.Comment #36
Anonymous (not verified) commentedComment #37
Anonymous (not verified) commentedMade patch apply to newest Drupal version
Comment #38
Anonymous (not verified) commentedComment #39
Anonymous (not verified) commentedWith test
Comment #40
wim leersGreat, thanks!
s/default/the default config entity/
We also need test coverage for the fail in #25 which was fixed by the interdiff in #31.
Comment #41
wim leersNeeds work for #40.
Comment #45
wim leersCan we still do this now that D8 is out?
Comment #46
dawehnerI doubt to be honest.
Comment #47
wim leersClarifying for the distant D9 future. And postponing for the same reason.
Comment #48
catchI can think of theoretical ways we could add bc for this, but it seems like the kind of @internal bc break we could save up for a major. There's no actual coupling/dependency here, it's just a string, so bumping down to minor.
Comment #50
xjmThis would be a minor-only addition and deprecation. Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!
Comment #51
xjmThere's nothing specific this is postponed on, so marking active.
Comment #59
damienmckennaPutting back to "needs work" as there is some code here, it needs to be turned into a merge request.
Comment #61
damienmckennaThe code needs some further tidying up.
Comment #62
berdirI have my doubts that this is worth doing. Everything that uses these strings would break unless we add some elaborate BC layer for it: https://search.tresbien.tech/search?q=config%3Asystem.menu%20-r%3Adrupal....
Also adding the return type is a BC break and unrelated. if phpstan complains, just add it to the baseline.
Comment #63
webflo commentedWe could rework the menu_ui module and create two separate forms. One would be used to edit the menu settings (config entity) and the other would be used to rearrange the menu links within the menu. Editing the menu settings would then become a local task.
Comment #64
webflo commented