Commit 07fe4198 authored by Gerhard Killesreiter's avatar Gerhard Killesreiter

#42388, Rehaul menu builder, patch by chx

parent 05c20c77
......@@ -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().
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment