public function RenderCheeseburgerMenuBlock::getMenuTree in Cheeseburger Menu 8.4
Same name and namespace in other branches
- 8 src/Controller/renderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\renderCheeseburgerMenuBlock::getMenuTree()
- 8.2 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::getMenuTree()
- 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\ControllerCode
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;
}