1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
5 – 7 menu_rebuild()

Populate the database representation of the menu.

This need only be called at the start of pages that modify the menu.

Related topics

▾ 13 functions call menu_rebuild()

aggregator_form_category_submit in modules/aggregator/aggregator.module
Process aggregator_form_category form submissions. @todo Add delete confirmation dialog.
aggregator_form_feed_submit in modules/aggregator/aggregator.module
Process aggregator_form_feed form submissions. @todo Add delete confirmation dialog.
menu_nodeapi in modules/menu/menu.module
Implementation of hook_nodeapi().
menu_overview in modules/menu/menu.module
Menu callback; present the main menu management page.
node_type_delete_confirm_submit in modules/node/
Process content type delete confirm submissions.
node_type_form_submit in modules/node/
Implementation of hook_form_submit().
system_modules_submit in modules/system/system.module
Submit callback; handles modules form submission.
system_settings_form_submit in modules/system/system.module
Execute the system_settings_form.
system_themes_submit in modules/system/system.module
system_update_1005 in modules/system/system.install
user_admin_perm_submit in modules/user/user.module
_locale_import_po in includes/
Parses Gettext Portable Object file information and inserts into database
_locale_string_edit_submit in includes/
Process string editing form submissions. Saves all translations of one string submitted from a form.


includes/, line 588

function menu_rebuild() {
  // Clear the page cache, so that changed menus are reflected for anonymous users.
  cache_clear_all('*', 'cache_page', TRUE);
  // Also clear the menu cache.
  cache_clear_all('*', 'cache_menu', TRUE);


  if (module_exists('menu')) {
    $menu = menu_get_menu();

    // Fill a queue of new menu items which are modifiable.
    $new_items = array();
    foreach ($menu['items'] as $mid => $item) {
      if ($mid < 0 && ($item['type'] & MENU_MODIFIABLE_BY_ADMIN)) {
        $new_items[$mid] = $item;

    $old_count = -1;
    // Save the new items updating the pids in each iteration
    while (($c = count($new_items)) && ($c != $old_count)) {
      $old_count = count($new_items);
      foreach ($new_items as $mid => $item) {
        // If the item has a valid parent, save it
        if ($item['pid'] >= 0) {
          // The new menu ID gets passed back by reference as $item['mid']
          // Fix parent IDs for the children of the menu item just saved
          if ($item['children']) {
            foreach ($item['children'] as $child) {
              if (isset($new_items[$child])) {
                $new_items[$child]['pid'] = $item['mid'];
          // remove the item
    // Rebuild the menu to account for the changes.

  // Reset the cached $menu in menu_get_item().
  menu_get_item(NULL, NULL, TRUE);