0

I need to edit the hook_menu function in my module. I need to add a new link to a menu, and edit the path for an existing link. Is this possible without creating a whole new module?

The only example in the docs for when hook_menu runs is when the module is enabled. Is there any other time it runs?

5
  • hook_menu(), together hook_menu_alter(), is invoked when menu definitions needs to be rebuild, which normally happens when any module is installed, removed, enabled, or disabled. The question is a little unclear, though. What do you mean by I need to edit the hook_menu() function in my module? Disable the module, edit the code, and re-enable the module.
    – apaderno
    Oct 8, 2018 at 20:29
  • @kiamlaluno Editing the code doesn't require disabling the module. If you edit the hook implementation, the menu will not show any updates. That is probably why the OP is asking. How do you rebuild the menu after editing a module's hook_menu()
    – mbomb007
    Sep 23, 2019 at 14:46
  • @mbomb007 Editing the code of a module doesn't tell Drupal that the menu definitions need to be rebuild. Drupal doesn't check the last time a module file has been changed, so it will not know the hook_menu() implementation has been possibly changed.
    – apaderno
    Sep 23, 2019 at 15:29
  • When a module is disabled, enabled, uninstalled, or installed, Drupal will rebuild the menu definitions. To do that, it will need to invoke every hook_menu() and hook_menu_alter() implementations. That is why disabling a module works.
    – apaderno
    Sep 23, 2019 at 16:04
  • It doesn't work for me.
    – mbomb007
    Sep 23, 2019 at 16:11

1 Answer 1

1

Clearing the cache the menu and routing tables will be reconstructed.

In the admin UI, go to:

/admin/config/development/performance

Using drush:

drush cache-clear all

Other methods are described here: How do I call the menu_rebuild function in Drupal 7?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.