You are here

public function MenuItems::getMenuTree in Simplify Menu 8.2

Same name and namespace in other branches
  1. 8 src/MenuItems.php \Drupal\simplify_menu\MenuItems::getMenuTree()

Get header menu links.

Parameters

string $menuId: Menu drupal id.

Return value

array Render array of menu items.

File

src/MenuItems.php, line 112

Class

MenuItems
Class MenuItems.

Namespace

Drupal\simplify_menu

Code

public function getMenuTree(string $menuId = 'main') : array {
  $this
    ->setActiveMenuTree($menuId);
  $parameters = new MenuTreeParameters();
  $parameters
    ->onlyEnabledLinks();
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $headerTreeLoad = $this->menuLinkTree
    ->load($menuId, $parameters);
  $headerTransform = $this->menuLinkTree
    ->transform($headerTreeLoad, $manipulators);
  return [
    'menu_tree' => $this
      ->simplifyLinks($headerTransform),
  ];
}