Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.362 diff -u -p -r1.362 menu.inc --- includes/menu.inc 11 Nov 2009 08:28:50 -0000 1.362 +++ includes/menu.inc 24 Nov 2009 21:09:04 -0000 @@ -2343,8 +2343,9 @@ function _menu_navigation_links_rebuild( $item['plid'] = $existing_item['plid']; } else { - // If it moved, put it at the top level in the new menu. - $item['plid'] = 0; + // It moved to a new menu, so let menu_link_save() try to find a + // valid parent based on path. + unset($item['plid']); } $item['has_children'] = $existing_item['has_children']; $item['updated'] = $existing_item['updated']; @@ -2543,7 +2544,6 @@ function _menu_delete_item($item, $force * saved. */ function menu_link_save(&$item) { - drupal_alter('menu_link', $item); // This is the easiest way to handle the unique internal path '', @@ -2569,14 +2569,12 @@ function menu_link_save(&$item) { } } + // The re-parenting process always needs to be invoked, since there is no + // guarantee that {menu_links} does not contain stale data caused by a + // re-parenting process that went wrong in a previous rebuild. + // 'plid' can be 0 (zero) for top-level links in a menu. if (isset($item['plid'])) { - if ($item['plid']) { - $parent = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['plid']))->fetchAssoc(); - } - else { - // Don't bother with the query - mlid can never equal zero.. - $parent = FALSE; - } + $parent = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['plid']))->fetchAssoc(); } else { $query = db_select('menu_links'); @@ -2585,10 +2583,9 @@ function menu_link_save(&$item) { if ($item['module'] == 'system') { $query->condition('module', 'system'); } - else { - // If not derived from a router item, we respect the specified menu name. - $query->condition('menu_name', $item['menu_name']); - } + // Always respect the link's menu name. Inheritance for router items is + // ensured in _menu_router_build(). + $query->condition('menu_name', $item['menu_name']); // Find the parent - it must be unique. $parent_path = $item['link_path']; @@ -2603,6 +2600,7 @@ function menu_link_save(&$item) { } } while ($parent === FALSE && $parent_path); } + // If a parent link was found, derive its menu. if ($parent !== FALSE) { $item['menu_name'] = $parent['menu_name']; } @@ -2636,7 +2634,7 @@ function menu_link_save(&$item) { ->execute(); } - if (!$item['plid']) { + if ($item['plid'] == 0) { $item['p1'] = $item['mlid']; for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) { $item["p$i"] = 0; @@ -3054,6 +3052,15 @@ function _menu_router_build($callbacks) $parent = $menu[$parent_path]; + // Try to inherit the menu name from parent router items. + if (!isset($item['menu_name'])) { + if (!isset($parent['menu_name'])) { + $parent['menu_name'] = db_query("SELECT menu_name FROM {menu_links} WHERE router_path = :router_path", array(':router_path' => $parent_path))->fetchColumn(); + } + if (!empty($parent['menu_name'])) { + $item['menu_name'] = $parent['menu_name']; + } + } if (!isset($item['tab_parent'])) { // Parent stores the parent of the path. $item['tab_parent'] = $parent_path;