Menu created out of order
sonictruth - October 13, 2009 - 01:19
| Project: | Menu Clone |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Description
Hello,
Thanks for the module. It has given me a good head start on another module that I am making.
I did however discover a bug in your code that needs to be addressed.
for ($depth = 1; $depth < 10; $depth++) {
$new_mlids = array();
$next_depth = $depth + 1;
foreach ($menu as &$mi) {
// Save the items at this depth
if ($mi['depth'] === $depth) {
$mi['old_mlid'] = $mi['mlid'];
$mi['menu_name'] = $menu_name;
unset($mi['mlid']);
menu_link_save($mi);
$new_mlids[$mi['old_mlid']] = $mi['mlid'];
}
elseif ($mi['depth'] === $next_depth) {
// Update plids on next level of items
$mi['plid'] = $new_mlids[$mi['plid']];
}
}This piece of code from line 46 assumes that the menu items are ordered by depth. Your db query on line 34 does not do this, instead they are returned in the order that they were created in the db. This messes up the cloned menu structure unless the menu items just happened to be created in the correct order.
My suggestion is to change the db_query on line 34 to this:
$rez = db_query('SELECT mlid FROM {menu_links} WHERE menu_name = "%s" ORDER BY depth', array($form_state['values']['parent']));Hope this helps.

#1
Okay, I just submitted an update which implements this. Once the robots have packaged it, please give it a try if you can.