function NavigationContentLinks::addLink

Ensure a route exists and add the link.

Parameters

string $link_name: The name of the link being added.

array $link: The link array, as defined in hook_menu_links_discovered_alter().

array $links: The existing array of links.

2 calls to NavigationContentLinks::addLink()
NavigationContentLinks::addCreateEntityLinks in core/modules/navigation/src/NavigationContentLinks.php
Add create links for an entity type.
NavigationContentLinks::addMenuLinks in core/modules/navigation/src/NavigationContentLinks.php
Add links to the Content menu, based on enabled modules.

File

core/modules/navigation/src/NavigationContentLinks.php, line 194

Class

NavigationContentLinks
Build the menu links for the Content menu.

Namespace

Drupal\navigation

Code

private function addLink(string $link_name, array $link, array &$links) : void {
    try {
        // Ensure the route exists (there is no separate "exists" method).
        $this->routeProvider
            ->getRouteByName($link['route_name']);
        $links[$link_name] = $link + [
            'menu_name' => 'content',
            'provider' => 'navigation',
        ];
    } catch (RouteNotFoundException $e) {
        // The module isn't installed, or the route (such as provided by a view)
        // has been deleted.
    }
}

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