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);
       }
     }
   }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Status: Active » Needs review
FileSize
1.87 KB

Direct back-port.

catch’s picture

Straight backport, code looks fine, can't be tested directly in core but it's already in D7, so RTBC.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community
pwolanin’s picture

Version: 6.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Needs work

I 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.

pwolanin’s picture

Title: back-port _menu_navigation_links_rebuild fix to 6.x » fix_menu_navigation_links_rebuild to correctly handle changing menu_name
pwolanin’s picture

pwolanin’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

pwolanin’s picture

hmm, something is not right indeed. Move links out of the admin section.