You are here

function nice_menus_build_tree in Nice Menus 8

Parameters

array $config:

Return value

mixed

1 call to nice_menus_build_tree()
NiceMenusBlock::build in src/Plugin/Block/NiceMenusBlock.php

File

./nice_menus.module, line 53
Module to enable CSS dropdown and flyout menus.

Code

function nice_menus_build_tree(array $config) {
  $menu_tree = \Drupal::service('menu.link_tree');
  $parameters = new MenuTreeParameters();

  // Set the active trail.
  $active_trail = \Drupal::service('menu.active_trail')
    ->getActiveTrailIds($config['menu_name']);
  $parameters
    ->setActiveTrail($active_trail);

  // set menu root.
  if ($config['menu_mlid']) {
    $parameters
      ->setRoot($config['menu_mlid']);
  }

  // set menu depth.
  if ($config['nice_menus_depth'] > 0) {
    $parameters
      ->setMaxDepth($config['nice_menus_depth']);
  }

  // TODO support nice_menus_respect_expand.
  $parameters
    ->excludeRoot()
    ->onlyEnabledLinks();
  $tree = $menu_tree
    ->load($config['menu_name'], $parameters);
  $manipulators = array(
    array(
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ),
    array(
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ),
  );
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  return $menu_tree
    ->build($tree);
}