You are here

protected function MenuSelectTreeBuilder::buildNestedMenu in Menu Select 8

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

Function to generate an array of the full menu.

Output keys of each menu link id to it's link title.

Parameters

array $menu_tree: Array of the menu tree.

string $menu_id: The menu ID.

string $current_link_id: The current link ID.

Return value

mixed The menu structure.

1 call to MenuSelectTreeBuilder::buildNestedMenu()
MenuSelectTreeBuilder::buildRenderedMenu in src/MenuSelectTreeBuilder.php
Builds a renderable array of the given menu tree.

File

src/MenuSelectTreeBuilder.php, line 99

Class

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

Namespace

Drupal\menu_select

Code

protected function buildNestedMenu(array $menu_tree, $menu_id, $current_link_id) {
  $nested_menu = [];
  foreach ($menu_tree as $data) {

    // Exclude the current link ID from becoming a parent of itself.
    if ($current_link_id === $data->link
      ->getPluginId()) {
      continue;
    }
    $menu_key = $this
      ->getMenuKey($menu_id, $data->link);
    $nested_menu[$menu_key]['data'] = $this
      ->generateLink($data->link, $menu_key);
    if (!empty($data->subtree)) {
      $nested_menu[$menu_key]['children'] = $this
        ->buildNestedMenu($data->subtree, $menu_id, $current_link_id);
    }
  }
  return $nested_menu;
}