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.
In #273137: Split Navigation to User and Administration menu I found a bug in function _menu_navigation_links_rebuild() that prevented any menu links except those at the very top level form being parented/re-parented to the correct menu via a specification in hook_menu.
Here's the 7.x fix, which needs to be backported to 6.x:
@@ -1863,7 +1880,6 @@ function _menu_navigation_links_rebuild(
$menu_links = array();
foreach ($menu as $path => $item) {
if ($item['_visible']) {
- $item = _menu_link_build($item);
$menu_links[$path] = $item;
$sort[$path] = $item['_number_parts'];
}
@@ -1882,7 +1898,7 @@ function _menu_navigation_links_rebuild(
'has_children',
'updated',
))
- ->condition('link_path', $item['link_path'])
+ ->condition('link_path', $item['path'])
->condition('module', 'system')
->execute()->fetchAssoc();
if ($existing_item) {
@@ -1892,17 +1908,22 @@ function _menu_navigation_links_rebuild(
$item['menu_name'] = $existing_item['menu_name'];
$item['plid'] = $existing_item['plid'];
}
+ else {
+ // If it moved, put it at the top level in the new menu.
+ $item['plid'] = 0;
+ }
$item['has_children'] = $existing_item['has_children'];
$item['updated'] = $existing_item['updated'];
}
if (!$existing_item || !$existing_item['customized']) {
+ $item = _menu_link_build($item);
menu_link_save($item);
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#6 | system-links-408338-6-D7.patch | 3.38 KB | pwolanin |
#1 | navigation-links-408338-1.patch | 1.87 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedDirect back-port.
Comment #2
catchStraight backport, code looks fine, can't be tested directly in core but it's already in D7, so RTBC.
Comment #3
pwolanin CreditAttribution: pwolanin commentedComment #4
pwolanin CreditAttribution: pwolanin commentedI tested more last night (and dreamed about this code) and I relize now that it's only (now) working more-or-less right when going form the default menu (empty menu_nam attribute in hook_menu) to some other menu. But, it does not work right in the reverse direction.
Comment #5
pwolanin CreditAttribution: pwolanin commentedComment #6
pwolanin CreditAttribution: pwolanin commentedComment #7
pwolanin CreditAttribution: pwolanin commentedComment #9
pwolanin CreditAttribution: pwolanin commentedhmm, something is not right indeed. Move links out of the admin section.