You are here

public function UltimenuManager::loadSubMenuTree in Ultimenu 8

1 call to UltimenuManager::loadSubMenuTree()
UltimenuManager::buildMenuTree in src/UltimenuManager.php
Build the menu to contain Ultimenu regions.

File

src/UltimenuManager.php, line 331

Class

UltimenuManager
Manages Ultimenu plugin.

Namespace

Drupal\ultimenu

Code

public function loadSubMenuTree($menu_name, $link_id = '', $title = '') {
  $build = [];
  if (empty($link_id)) {
    return $build;
  }
  $level = 1;
  $depth = 4;
  $menu_tree = $this->menuTree;
  $parameters = $menu_tree
    ->getCurrentRouteMenuTreeParameters($menu_name);
  $parameters
    ->setRoot($link_id)
    ->excludeRoot()
    ->onlyEnabledLinks();
  $parameters
    ->setMaxDepth(min($level + $depth - 1, $menu_tree
    ->maxDepth()));
  $tree = $menu_tree
    ->load($menu_name, $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  if ($tree) {
    $build['content'] = $menu_tree
      ->build($tree);
    $css_name = Html::cleanCssIdentifier(Unicode::strtolower($menu_name . '-' . $title));
    $build['#attributes']['class'] = [
      'ultimenusub',
      'ultimenusub--' . $css_name,
    ];
    $build['#theme_wrappers'][] = 'container';
  }
  return $build;
}