diff options
author | Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org> | 2006-03-15 08:49:24 +0000 |
---|---|---|
committer | Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org> | 2006-03-15 08:49:24 +0000 |
commit | 07fe4198ad8026fc973a65b79a4706bc281ddd51 (patch) | |
tree | 4e4f8595b7693956bca5371e16f5810846c1b3dd /includes | |
parent | 05c20c778190696c2f95e1a4f04bc51dafe811d1 (diff) | |
download | brdo-07fe4198ad8026fc973a65b79a4706bc281ddd51.tar.gz brdo-07fe4198ad8026fc973a65b79a4706bc281ddd51.tar.bz2 |
#42388, Rehaul menu builder, patch by chx
Diffstat (limited to 'includes')
-rw-r--r-- | includes/menu.inc | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/includes/menu.inc b/includes/menu.inc index 69fa748fa..71db7aee0 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -592,31 +592,28 @@ function menu_rebuild() { } } - reset($new_items); - while (list($old_mid, $item) = each($new_items)) { - if ($item['pid'] < 0 && isset($new_items[$item['pid']])) { - // The item's parent has a temporary ID and is still in the queue. Put - // the item at the back of the queue so it may be saved after the - // parent item has recieved a new ID. - $new_items[$old_mid] = $item; - } - else { - // The new menu ID gets passed back by reference as $item['mid'] - menu_save_item($item); - - // Fix parent IDs for menu items just added. - if ($item['children']) { - foreach ($item['children'] as $child) { - if (isset($new_items[$child])) { - $new_items[$child]['pid'] = $item['mid']; + // Save the new items updating the pids in each iteration + while (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'] + menu_save_item($item); + // 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 + unset($new_items[$mid]); } } - - // Rebuild the menu to account for the changes. - _menu_build(); } + // Rebuild the menu to account for the changes. + _menu_build(); } // Reset the cached $menu in menu_get_item(). |