views:

134

answers:

3

When I enable a new menu in Drupal (for example, mymodule), Drupal should be able to get the menu items from mymodule_menu (hook_menu), process the items and insert the menu items to menu_router and menu_links table.

However, my Drupal fails to do so. Each time I enable a module (written by me or modules contributed by others, or core modules), Drupal does not seem to get the new information. The menu items defined in the newly enabled module are not processed and inserted to Drupal's menu system. That means the newly enabled module has no chance to work-- because it's inaccessible.

I did fix this by manually insert the menu item information for the new module into the menu_router and menu_links table and the new menu started working. But this is a nightmare if I have to do this each time I enable a module.

Any one has ever had the same problem? How to fix this?

Thank you in advance.

A: 

I would not use any SQL to interact with the menu tables, something nasty could happen if you edit the wrong record.

You must have an error in your hook_menu code. Can you paste it?

Also, if you are developing a module that has menu entries, I find that its handy to call these two functions inside of mymodule_init() when adding/removing links:

cache_clear_all()
menu_router_build()

That will flush all cache and rebuild the menu and anything invoking hook_menu. If it doesn't appear after that, then your code has a bug. I'd like to see it.

Kevin
A: 

You didn't report which Drupal version are you using, but in Drupal 6, the implementations of hook_menu() are not invoked, if not in some occasions (when a module is installed, or when modules updates are executed, in example).

If your module changed the menu callbacks, but it has not an update to execute, you can add an update function containing the following code:

// Change the name of the function to match the module name.
// Change the update number to the correct one for your case.
function custom_module_update_6201() {
  if (!variable_get('menu_rebuild_needed', FALSE)) {
    variable_set('menu_rebuild_needed', TRUE);
  }
}

The variable is checked from index.php, and if its value is TRUE, then Drupal will automatically rebuild the menus.

kiamlaluno
A: 

please provide code, I think there is some bug

Igor Rodinov