function AdminTest::getTopLevelMenuLinks

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::getTopLevelMenuLinks()
  2. 10 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::getTopLevelMenuLinks()
  3. 11.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::getTopLevelMenuLinks()

Returns all top level menu links.

Return value

\Drupal\Core\Menu\MenuLinkInterface[]

1 call to AdminTest::getTopLevelMenuLinks()
AdminTest::testAdminPages in core/modules/system/tests/src/Functional/System/AdminTest.php
Tests output on administrative listing pages.

File

core/modules/system/tests/src/Functional/System/AdminTest.php, line 129

Class

AdminTest
Tests output on administrative pages and compact mode functionality.

Namespace

Drupal\Tests\system\Functional\System

Code

protected function getTopLevelMenuLinks() {
    $menu_tree = \Drupal::menuTree();
    // The system.admin link is normally the parent of all top-level admin links.
    $parameters = new MenuTreeParameters();
    $parameters->setRoot('system.admin')
        ->excludeRoot()
        ->setTopLevelOnly()
        ->onlyEnabledLinks();
    $tree = $menu_tree->load(NULL, $parameters);
    $manipulators = [
        [
            'callable' => 'menu.default_tree_manipulators:checkAccess',
        ],
        [
            'callable' => 'menu.default_tree_manipulators:flatten',
        ],
    ];
    $tree = $menu_tree->transform($tree, $manipulators);
    // Transform the tree to a list of menu links.
    $menu_links = [];
    foreach ($tree as $element) {
        $menu_links[] = $element->link;
    }
    return $menu_links;
}

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