public function Render::renderMenu in Bamboo Twig 8.2
Same name and namespace in other branches
- 8.5 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderMenu()
- 8.3 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderMenu()
- 8.4 bamboo_twig_loader/src/TwigExtension/Render.php \Drupal\bamboo_twig_loader\TwigExtension\Render::renderMenu()
Returns the render array for Drupal menu.
Parameters
string $menu_name: The name of the menu.
int $level: (optional) Initial menu level.
int $depth: (optional) Maximum number of menu levels to display.
Return value
array A render array for the menu.
File
- bamboo_twig_loader/
src/ TwigExtension/ Render.php, line 295
Class
- Render
- Provides some renderer as Twig Extensions.
Namespace
Drupal\bamboo_twig_loader\TwigExtensionCode
public function renderMenu($menu_name, $level = 1, $depth = 0) {
// Lazy load the entity type manager only when needed.
$menuLinkTree = $this
->getMenuLinkTree();
$parameters = $menuLinkTree
->getCurrentRouteMenuTreeParameters($menu_name);
// Adjust the menu tree parameters based on the block's configuration.
$parameters
->setMinDepth($level);
// When the depth is configured to zero, there is no depth limit. When depth
// is non-zero, it indicates the number of levels that must be displayed.
// Hence this is a relative depth that we must convert to an actual
// (absolute) depth, that may never exceed the maximum depth.
if ($depth > 0) {
$parameters
->setMaxDepth(min($level + $depth - 1, $menuLinkTree
->maxDepth()));
}
$parameters
->onlyEnabledLinks();
$parameters->expandedParents = [];
$tree = $menuLinkTree
->load($menu_name, $parameters);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:checkAccess',
],
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
$tree = $menuLinkTree
->transform($tree, $manipulators);
return $menuLinkTree
->build($tree);
}