menu_get_menu

Versions
4.6 – 5
menu_get_menu()

Return the menu data structure.

The returned structure contains much information that is useful only internally in the menu system. External modules are likely to need only the ['visible'] element of the returned array. All menu items that are accessible to the current user and not hidden will be present here, so modules and themes can use this structure to build their own representations of the menu.

$menu['visible'] will contain an associative array, the keys of which are menu IDs. The values of this array are themselves associative arrays, with the following key-value pairs defined:

  • 'title' - The displayed title of the menu or menu item. It will already have been translated by the locale system.
  • 'description' - The description (link title attribute) of the menu item. It will already have been translated by the locale system.
  • 'path' - The Drupal path to the menu item. A link to a particular item can thus be constructed with l($item['title'], $item['path'], array('title' => $item['description'])).
  • 'children' - A linear list of the menu ID's of this item's children.

Menu ID 0 is the "root" of the menu. The children of this item are the menus themselves (they will have no associated path). Menu ID 1 will always be one of these children; it is the default "Navigation" menu.

Related topics

▾ 18 functions call menu_get_menu()

menu_block in modules/menu.module
Implementation of hook_block().
menu_disable_item in modules/menu.module
Menu callback; hide a menu item.
menu_edit_item_form in modules/menu.module
Present the menu item editing form.
menu_edit_item_save in modules/menu.module
Save changes to a menu item into the database.
menu_execute_active_handler in includes/menu.inc
Execute the handler associated with the active menu item.
menu_get_active_breadcrumb in includes/menu.inc
Returns an array of rendered menu items in the active breadcrumb trail.
menu_get_active_nontask_item in includes/menu.inc
Returns the ID of the current menu item or, if the current item is a local task, the menu item to which this task is attached.
menu_get_active_title in includes/menu.inc
Returns the title of the active menu item.
menu_item_link in includes/menu.inc
Returns the rendered link to a menu item.
menu_overview_tree in modules/menu.module
Present the menu tree, rendered along with links to edit menu items.
menu_overview_tree_rows in modules/menu.module
menu_parent_options in modules/menu.module
Return a list of menu items that are valid possible parents for the given menu item.
menu_rebuild in includes/menu.inc
Populate the database representation of the menu.
menu_set_active_item in includes/menu.inc
Sets the path of the active menu item.
menu_tree in includes/menu.inc
Returns a rendered menu tree.
_menu_get_active_trail in includes/menu.inc
Returns an array with the menu items that lead to the current menu item.
_menu_item_is_accessible in includes/menu.inc
Determine whether the given menu item is accessible to the current user.
_menu_sort in includes/menu.inc
Comparator routine for use in sorting menu items.

Code

includes/menu.inc, line 197

<?php
function menu_get_menu() {
  global $_menu;
  global $user;
  global $locale;

  if (!isset($_menu['items'])) {
    // _menu_build() may indirectly call this function, so prevent infinite loops.
    $_menu['items'] = array();

    $cid = "menu:$user->uid:$locale";
    if ($cached = cache_get($cid)) {
      $_menu = unserialize($cached->data);
    }
    else {
      _menu_build();
      // Cache the menu structure for this user, to expire after one day.
      cache_set($cid, serialize($_menu), time() + (60 * 60 * 24));
    }

    // Make sure items that cannot be cached are added.
    _menu_append_contextual_items();
  }

  return $_menu;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.