Problem/Motivation
Recipes commonly want to reconfigure menus in some ways. However, not all menu links are created equal: some are static menu links defined in code, and need to be overridden using core's \Drupal\Core\Menu\StaticMenuLinkOverrides service. There's no way for config actions to do this.
Proposed resolution
Add a thin wrapper around \Drupal\Core\Menu\StaticMenuLinkOverrides::saveOverride() and ::deleteOverride(), like so:
config:
actions:
core.menu.static_menu_link_overrides:
overrideMenuLinks:
some.link.id:
enabled: false
weight: 10
some_other.link_id: null
Each link to override is identified by its ID. The value corresponding to that ID can either be an array (the overridden values, which will be merged with the original definition so as to change as little as possible), or NULL to indicate that any previous override should be removed.
API changes
We'll get a new config action, but no other API changes will be needed.
Issue fork drupal-3569949
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:
- 3569949-add-a-config
changes, plain diff MR !14521
Comments
Comment #3
phenaproximaStill needs a test but I wrote the plugin itself lickety-split.
Comment #4
thejimbirch commentedThis looks promising. I suspect this is primarily to override menu link overrides from distributions or install profiles?
Am i correct that if the link doesn't exist, it only logs a warning, the recipe does not fail?
Comment #5
phenaproximaThis will NOT override menu links that are entities, e.g., anything in the
content/menu_link_contentdirectory.It's only effective for menu links defined in code, e.g., in
MODULE.links.menu.ymlfiles.You are indeed correct.
Comment #6
godotislateOne nit on the MR. Seems straightforward enough, but test TBD as mentioned.
Comment #7
phenaproximaWrote a test! Another round of review?
Comment #8
thejimbirch commentedThanks for the clarification! This should be included in the change record/docs for recipe authors. It provides a definite use case with tangible examples.
Comment #9
thejimbirch commentedErrant comma removed. Marking as RTBC.
Comment #10
larowlanCommitted to main and backported to 11.x
I think it would be good to add a change record to announce this new action - if someone could add that and remove the tag?
Thanks
Comment #15
phenaproximaDone. https://www.drupal.org/node/3570506