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

Command icon 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

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review

Still needs a test but I wrote the plugin itself lickety-split.

thejimbirch’s picture

Issue tags: +Config Actions

This looks promising. I suspect this is primarily to override menu link overrides from distributions or install profiles?

        catch (PluginNotFoundException) {
          $this->logger->warning('The @link_id menu link was not overridden because it does not exist.', [
            '@link_id' => $link_id,
          ]);
        }

Am i correct that if the link doesn't exist, it only logs a warning, the recipe does not fail?

phenaproxima’s picture

I suspect this is primarily to override menu link overrides from distributions or install profiles?

This will NOT override menu links that are entities, e.g., anything in the content/menu_link_content directory.

It's only effective for menu links defined in code, e.g., in MODULE.links.menu.yml files.

Am i correct that if the link doesn't exist, it only logs a warning, the recipe does not fail?

You are indeed correct.

godotislate’s picture

One nit on the MR. Seems straightforward enough, but test TBD as mentioned.

phenaproxima’s picture

Wrote a test! Another round of review?

thejimbirch’s picture

This will NOT override menu links that are entities, e.g., anything in the content/menu_link_content directory.

It's only effective for menu links defined in code, e.g., in MODULE.links.menu.yml files.

Thanks for the clarification! This should be included in the change record/docs for recipe authors. It provides a definite use case with tangible examples.

thejimbirch’s picture

Status: Needs review » Reviewed & tested by the community

Errant comma removed. Marking as RTBC.

larowlan’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs change record

Committed 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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • larowlan committed 48ed5e0c on 11.x
    feat: #3569949 Add a config action to override static menu links
    
    By:...

  • larowlan committed a13a7ca2 on main
    feat: #3569949 Add a config action to override static menu links
    
    By:...
phenaproxima’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.