You are here

function admin_menu_add_item in Administration menu 5.3

Same name and namespace in other branches
  1. 5.2 admin_menu.module \admin_menu_add_item()

Add a custom menu item.

Parameters

$_admin_menu: An array containing the complete administration menu structure, passed by reference.

$pid: The parent menu item id.

$item: An menu item array for the menu system. May contain the key 'weight' to adjust the item's weight.

$mid: (Optional) The menu item id to use. Should be specified for already existing menu items that are copied/relocated elsewhere.

Return value

The id of the new menu item.

3 calls to admin_menu_add_item()
admin_menu_adjust_items in ./admin_menu.inc
Add some hard-coded features for better user experience.
admin_menu_admin_menu in ./admin_menu.module
Implementation of hook_admin_menu().
admin_menu_copy_items in ./admin_menu.inc
Recursively copy menu items from a source parent menu item to a target item.

File

./admin_menu.module, line 549
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_add_item(&$_admin_menu, $pid, $item, $mid = NULL) {
  static $custom_mid;
  if (empty($item['path'])) {
    return FALSE;
  }
  $item['pid'] = $pid;
  $item['children'] = array();
  if (!isset($custom_mid)) {
    $custom_mid = max(array_keys($_admin_menu)) + 10000;
  }
  if (!isset($mid)) {
    $mid = $custom_mid++;
  }
  else {

    // Ensure we have an integer.
    $mid = (int) $mid;
  }
  $_admin_menu[$mid] = $item;
  $_admin_menu[$pid]['children'][] = $mid;
  $_admin_menu['index'][$item['path']] = $mid;
  admin_menu_item_url($_admin_menu, $mid);

  // Sort items.
  usort($_admin_menu[$pid]['children'], '_admin_menu_sort');
  return $mid;
}