function MenuUiHooks::systemBreadcrumbAlter

Implements hook_system_breadcrumb_alter().

File

core/modules/menu_ui/src/Hook/MenuUiHooks.php, line 258

Class

MenuUiHooks
Hook implementations for menu_ui.

Namespace

Drupal\menu_ui\Hook

Code

public function systemBreadcrumbAlter(Breadcrumb $breadcrumb, RouteMatchInterface $route_match, array $context) {
    // Custom breadcrumb behavior for editing menu links, we append a link to
    // the menu in which the link is found.
    if ($route_match->getRouteName() == 'menu_ui.link_edit' && ($menu_link = $route_match->getParameter('menu_link_plugin'))) {
        if ($menu_link instanceof MenuLinkInterface) {
            // Add a link to the menu admin screen.
            $menu = Menu::load($menu_link->getMenuName());
            $breadcrumb->addLink(Link::createFromRoute($menu->label(), 'entity.menu.edit_form', [
                'menu' => $menu->id(),
            ]));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.