You are here

protected function AdminTest::getTopLevelMenuLinks in Drupal 10

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

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;
}