开发者

Drupal: How to Rebuild Menu Navigation

开发者 https://www.devze.com 2023-02-14 11:51 出处:网络
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

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 th开发者_开发百科ose tools are what I'm after.


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.


Here is another option for when you're not able to access the site or do not have Devel or Drush installed. Create a file such as rebuild.php and place it in your Drupal root (though it doesn't matter because chdir will switch to the specified Drupal root). Then after you visit that script it should rebuild the menu's and all should then be well on the site.

<?php
  // Bootstrap
  // Change chdir to the full path of your Drupal root
  chdir('/home/myusername/public_html/');
  define('DRUPAL_ROOT', getcwd());
  require_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  // Rebuild
  menu_rebuild();
?>


variable_set('menu_rebuild_needed', TRUE);


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;


Visiting the modules list page generally rebuilds the menus.

You can also try installing Dev modules Enable the dev block and you have a link for rebuild menus.


There are many ways to do it but the best way to do it is to use the devel module. Once you enable the module then go to blocks and enable the devel block on ur side bar. Then refer to the red box in the image

http://cyrve.com/screenshots/devel_theme_snap-20080113-205127.jpg

It has an option for to clear the menu cache. The location of the block will depend on where you place the block.


If you have the Devel module installed, you can go to the menus configuration page (/admin/build/menu) and then select Devel menu.

Inside that page will appear a Rebuild menus options.


In D7, the menus configuration page has moved to admin/structure/menu/ .

This little trick is the great way to get the menu router to rebuild without cluttering up the UI with another block.

0

精彩评论

暂无评论...
验证码 换一张
取 消