Change the deriver class of a menu link

Created on 21 November 2024, 4 months ago

Problem/Motivation

We need to remove some of the admin toolbar links for our project. I've attempted to override the 'admin_toolbar_tools.extra_links' deriver class, "ExtraLinks", with a custom one. One thing I tried is to define the same menu link in the menu.yml file in my custom module, changing the deriver class, but I think this is not correct, is it a better way to do it?

Thanks in advance.

💬 Support request
Status

Active

Version

10.4

Component

menu system

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @clgarciab
  • 🇦🇺Australia nterbogt

    This ticket is best placed on the admin_toolbar module rather than core.

    That said, you can't currently override a deriver as far as I'm aware. The code to do that doesn't exist, see Allow base plugin definition to be altered before derived Active .

    You can however override the menu links by using a module hook. Here is an example from our codebase.

    /**
     * Implements hook_menu_links_discovered_alter().
     */
    function MY_MODULE_menu_links_discovered_alter(&$links) {
      foreach ($links as $route_name => $link) {
        // Remove all the individual views from the menu.
        if (\str_starts_with($route_name, 'admin_toolbar_tools.extra_links:views_ui') && !\in_array($route_name, ['admin_toolbar_tools.extra_links:views_ui.add', 'admin_toolbar_tools.extra_links:views_ui.field_list'])) {
          unset($links[$route_name]);
        }
      }
    }
    
Production build 0.71.5 2024