I have created a custom module with some inc files for different functionalities, these inc files adds config pages for admin but i had to define all urls in .module file.

is it possible to use hook_menu in inc files as well, i already used it once in .module file. what i need is menu should be added from inc file itself.


You couldn't implement a single hook in the module twice.

Instead you can define a custom helper function like _MODULE_include_menu() in the .inc file and then use it in the main .module like:

function MODULE_menu() {
  $items = array();
  $items += _MODULE_include_menu();
  return $items;
  • Nor can you implement a hook in an include file (unless it's explicitly included, or in a special module hook file as provided by hook_hook_info()) - general advice is to implement hooks in modules only. The method in this answer is as good a way to do it as any, though it doesn't check for potential duplicates ;) – Clive Jun 25 '15 at 13:25
  • Sure. _MODULE_include_menu() IS NOT an implementation, this is just a helper function. – tonystar Jun 25 '15 at 13:26
  • This is the approach I take to abstract and simplify some hooks. Just invoke your helper functions inside of the actual hook. – Matt Glaman Jun 25 '15 at 13:30
  • Exactly, @Matt Glaman. Also I'm usually trying to leave only hook implementations in the main .module file and to move all the rest in the .inc files. – tonystar Jun 25 '15 at 13:33

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.