You are here

protected function AdminTest::getTopLevelMenuLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/AdminTest.php \Drupal\system\Tests\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/src/Tests/System/AdminTest.php
Tests output on administrative listing pages.

File

core/modules/system/src/Tests/System/AdminTest.php, line 126
Contains \Drupal\system\Tests\System\AdminTest.

Class

AdminTest
Tests output on administrative pages and compact mode functionality.

Namespace

Drupal\system\Tests\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 = array(
    array(
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ),
    array(
      'callable' => 'menu.default_tree_manipulators:flatten',
    ),
  );
  $tree = $menu_tree
    ->transform($tree, $manipulators);

  // Transform the tree to a list of menu links.
  $menu_links = array();
  foreach ($tree as $element) {
    $menu_links[] = $element->link;
  }
  return $menu_links;
}