You are here

public function MenuSelectTreeBuilder::buildRenderedMenu in Menu Select 8

Same name and namespace in other branches
  1. 2.0.x src/MenuSelectTreeBuilder.php \Drupal\menu_select\MenuSelectTreeBuilder::buildRenderedMenu()

Builds a renderable array of the given menu tree.

Parameters

array $menu_tree: The menu tree.

string $menu_id: The machine name of the menu being built.

string $menu_label: The label of the menu being built.

string $current_link_id: The current link plugin ID, used for exclusion.

Return value

array A renderable array.

Overrides MenuSelectTreeBuilderInterface::buildRenderedMenu

File

src/MenuSelectTreeBuilder.php, line 55

Class

MenuSelectTreeBuilder
A service for building out the menu trees used in menu select.

Namespace

Drupal\menu_select

Code

public function buildRenderedMenu(array $menu_tree, $menu_id, $menu_label, $current_link_id) {
  $menu_key = $this
    ->getMenuKey($menu_id);
  $items[$menu_key] = [
    'data' => $this
      ->generateMenuLink($menu_label, $this
      ->getMenuKey($menu_id)),
  ];
  if (!empty($menu_tree)) {
    $items[$menu_key]['children'] = $this
      ->buildNestedMenu($menu_tree, $menu_id, $current_link_id);
  }
  $build = [
    '#theme' => 'item_list',
    '#list_type' => 'ul',
    '#wrapper_attributes' => [
      'class' => [
        'menu-select-menu-hierarchy',
        'js-menu-select-menu-hierarchy',
      ],
    ],
    '#attributes' => [
      'class' => [
        'menu-select-menu-level',
        'js-menu-select-menu-level',
      ],
    ],
    '#items' => $items,
  ];
  return $build;
}