Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal: How to Rebuild Menu Navigation

In Drupal 7.0, when I change a routing path/menu from the type MENU_NORMAL_ITEM to the type MENU_CALLBACK, Drupal 7.0 does not remove the item from the menu_links table. I'm not sure if this is a bug or not, but I've filed one with the core team.

With that context in place, is there a way to force Drupal to do a rebuild of all its navigation menus? The bug I've described above is happening even when I clear out Drupal's cache after changing a Menu item.

I know I can rename an individual menu route, clear cache/refresh, and then name the item back to get any individual route/menu link flushed. I'm looking for a single command I can run (or function to call, or set of commands) and know all the menu navigation is up to date without worrying I've hosed some other part of the system by messing with internals.

Does this exist? If you're going to mention drush or devel, you're awesome, but specific instructions on those tools are what I'm after.

like image 962
Alan Storm Avatar asked Mar 03 '11 18:03

Alan Storm


People also ask

How do I change the navigation bar in Drupal 8?

Find and click the control for “Menus.” Look for the menu you wish to edit and click the button to “Edit menu” in the right column. In this example, I am going to edit the Main navigation menu. In this screen, you'll see all of the components that make up that particular menu.


2 Answers

I came across the same problem. I switched from MENU_NORMAL_ITEM to MENU_CALLBACK and could not get rid of the menu items in the navigation block. I tried a couple of the solutions above with no success. What worked for me was commenting out my menu items in hook_menu, clearing cache, re-enabling them and clearing cache once again.

This is what I returned in Hook_menu to clear all menu items:

return array(); //$items;

like image 53
leekei Avatar answered Oct 10 '22 17:10

leekei


Note that although there are options to rebuild the menu (see the other answers), these might or might not work to clean up issues with menu links.

Rebuilding the menu just rebuilds the menu router items and the menu links as far as they are automatically generated based on the menu router items. There are known issues with that, for example re-parenting menu links (http://drupal.org/node/550254). If menu links have been customized or added manually (or Drupal thinks they have been changed.. ), then these will not be touched.

As mentioned in another question already, the tight coupling between these two systems will probably be changed in D8 so that you will have to declare menu links separatly from menu router items.

like image 36
Berdir Avatar answered Oct 10 '22 17:10

Berdir