You are here

public function MenuLinkTree::build in Colossal Menu 8

Same name and namespace in other branches
  1. 2.x src/Menu/MenuLinkTree.php \Drupal\colossal_menu\Menu\MenuLinkTree::build()

Builds a renderable array from a menu tree.

The menu item's LI element is given one of the following classes:

  • expanded: The menu item is showing its submenu.
  • collapsed: The menu item has a submenu that is not shown.
  • leaf: The menu item has no submenu.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: A data structure representing the tree, as returned from MenuLinkTreeInterface::load().

Return value

array A renderable array.

Overrides MenuLinkTree::build

File

src/Menu/MenuLinkTree.php, line 81

Class

MenuLinkTree
Implements the loading, transforming and rendering of menu link trees.

Namespace

Drupal\colossal_menu\Menu

Code

public function build(array $tree) {
  $build = parent::build($tree);

  // Use a custom theme.
  if (isset($build['#theme'])) {
    $build['#theme'] = 'colossal_menu__' . strtr($build['#menu_name'], '-', '_');
  }
  if (!empty($build['#items'])) {
    $this
      ->addItemContent($build['#items']);
  }
  return $build;
}