You are here

public function RenderCheeseburgerMenuBlock::getMenuTree in Cheeseburger Menu 8.4

Same name and namespace in other branches
  1. 8 src/Controller/renderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\renderCheeseburgerMenuBlock::getMenuTree()
  2. 8.2 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::getMenuTree()
  3. 8.3 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::getMenuTree()

Returning menu tree data.

File

src/Controller/RenderCheeseburgerMenuBlock.php, line 334
Controller used for rendering block.

Class

RenderCheeseburgerMenuBlock
Class RenderCheeseburgerMenuBlock.

Namespace

Drupal\cheeseburger_menu\Controller

Code

public function getMenuTree($menu, $depth = NULL) {
  $menu_tree = $this->menuTree;
  $menu_tree_parameters = new MenuTreeParameters();
  $menu_tree_parameters
    ->onlyEnabledLinks();
  if (!is_null($depth) && is_numeric($depth) && $depth > 0) {
    $menu_tree_parameters
      ->setMaxDepth($depth);
  }
  $tree = $menu_tree
    ->load($menu, $menu_tree_parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  $menu_build = $menu_tree
    ->build($tree);
  $new_tree = [];
  if (array_key_exists('#items', $menu_build)) {
    if (is_array($menu_build['#items']) || is_object($menu_build['#items'])) {
      $new_tree = $this
        ->formatMenuArray($menu_build['#items']);
    }
  }
  return $new_tree;
}