function NavigationContentLinks::addMenuLinks

Same name in other branches
  1. 10 core/modules/navigation/src/NavigationContentLinks.php \Drupal\navigation\NavigationContentLinks::addMenuLinks()

Add links to the Content menu, based on enabled modules.

Parameters

array $links: The array of links being altered.

File

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

Class

NavigationContentLinks
Build the menu links for the Content menu.

Namespace

Drupal\navigation

Code

public function addMenuLinks(array &$links) : void {
    // First, add the top-level menu items.
    // @todo Consider turning this into a data object so we can avoid typos in
    // array keys.
    $content_links = [
        'navigation.create' => [
            'route_name' => 'node.add_page',
            'title' => $this->t('Create'),
            'weight' => -10,
        ],
        'navigation.content' => [
            'route_name' => 'view.content.page_1',
            'title' => $this->t('Content'),
        ],
        'navigation.files' => [
            'route_name' => 'view.files.page_1',
            'title' => $this->t('Files'),
        ],
        'navigation.media' => [
            'route_name' => 'view.media.media_page_list',
            'title' => $this->t('Media'),
        ],
        'navigation.blocks' => [
            'route_name' => 'view.block_content.page_1',
            'title' => $this->t('Blocks'),
        ],
    ];
    foreach ($content_links as $link_name => $link) {
        $this->addLink($link_name, $link, $links);
    }
    // Add supported add links under the Create button.
    $this->addCreateEntityLinks('node_type', 'node.add', $links);
    $this->addCreateEntityLinks('media_type', 'entity.media.add_form', $links, [
        'document',
        'image',
    ]);
    // Finally, add the bundleless User link and pin it to the bottom.
    $this->addLink('navigation.create.user', [
        'route_name' => 'user.admin_create',
        'title' => $this->t('User'),
        'parent' => 'navigation.create',
        'weight' => 100,
    ], $links);
}

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