Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comments
Comment #1
Garrett Albright CreditAttribution: Garrett Albright commentedOkay, I just submitted an update which implements this. Once the robots have packaged it, please give it a try if you can.
Comment #2
perandre CreditAttribution: perandre commentedThe dev version (May 09) did not work, but the lates in CVS worked fine. Great work! Sorry to see it abandoned.
Comment #3
malc0mn CreditAttribution: malc0mn commentedperandre: the current version is a full rewrite of the original module in which this issue is also properly addressed. Menu items are saved to the DB in the same order as the menu is built up, just as the Drupal core Menu module handles this.
Comment #4
perandre CreditAttribution: perandre commentedWell done! Looking forward to test.