You are here

protected function CoffeeController::getMenuTreeElements in Coffee 8

Retrieves the menu tree elements for the given menu.

Every element returned by this method is already access checked.

Parameters

string $menu_name: The menu name.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] A flatten array of menu link tree elements for the given menu.

1 call to CoffeeController::getMenuTreeElements()
CoffeeController::coffeeData in src/Controller/CoffeeController.php
Outputs the data that is used for the Coffee autocompletion in JSON.

File

src/Controller/CoffeeController.php, line 158

Class

CoffeeController
Provides route responses for coffee.module.

Namespace

Drupal\coffee\Controller

Code

protected function getMenuTreeElements($menu_name) {
  $parameters = new MenuTreeParameters();
  $tree = $this->menuLinkTree
    ->load($menu_name, $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkNodeAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:flatten',
    ],
  ];
  $tree = $this->menuLinkTree
    ->transform($tree, $manipulators);

  // Top-level inaccessible links are *not* removed; it is up
  // to the code doing something with the tree to exclude inaccessible links.
  // @see menu.default_tree_manipulators:checkAccess
  foreach ($tree as $key => $element) {
    if (!$element->access
      ->isAllowed()) {
      unset($tree[$key]);
    }
  }
  return $tree;
}