menu_build_tree

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 menu_build_tree($menu_name, array $parameters = array())

Build a menu tree, translate links, and check access.

Parameters

$menu_name The name of the menu.

$parameters (optional) An associative array of build parameters. Possible keys:

  • expanded: An array of parent link ids to return only menu links that are children of one of the plids in this list. If empty, the whole menu tree is built, unless 'only_active_trail' is TRUE.
  • active_trail: An array of mlids, representing the coordinates of the currently active menu link.
  • only_active_trail: Whether to only return links that are in the active trail. This option is ignored, if 'expanded' is non-empty. Internally used for breadcrumbs.
  • min_depth: The minimum depth of menu links in the resulting tree. Defaults to 1, which is the default to build a whole tree for a menu, i.e. excluding menu container itself.
  • max_depth: The maximum depth of menu links in the resulting tree.

Return value

A fully built menu tree.

Related topics

▾ 3 functions call menu_build_tree()

menu_tree_all_data in includes/menu.inc
Get the data structure representing a named menu tree.
menu_tree_page_data in includes/menu.inc
Get the data structure representing a named menu tree, based on the current page.
toolbar_get_menu_tree in modules/toolbar/toolbar.module
Get only the top level items below the 'admin' path.

Code

includes/menu.inc, line 1332

<?php
function menu_build_tree($menu_name, array $parameters = array()) {
  // Build the menu tree.
  $data = _menu_build_tree($menu_name, $parameters);
  // Check access for the current user to each item in the tree.
  menu_tree_check_access($data['tree'], $data['node_links']);
  return $data['tree'];
}
?>