function AdminTest::getTopLevelMenuLinks

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::getTopLevelMenuLinks()
  2. 8.9.x 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\MenuLinkTreeElement[]

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 136

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',
    ],
  ];
  return $menu_tree->transform($tree, $manipulators);
}

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