Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a single tiny change to a core module. I copied it into my site modules directory. I am curious as to whther I can simply override it's hook_menu() method in my copy so as not to carry over all the additional code which the core version provides?

Similar to theme inheritance, do modules support anything similar?

share|improve this question

There's no inheritance for modules, but much of the functionality they provide can be altered using hooks (search this page for _alter and you'll see the ones core provides).

Specifically for items defined in hook_menu(), you can use hook_menu_alter(), e.g.

function MYMODULE_menu_alter(&$items) {
  // Replace the page callback for the foo/bar path
  $items['foo/bar']['page callback'] = 'MYMODULE_some_function;

If I've misunderstood and you mean you literally want to inherit from a module, like subclassing a class, and just change a couple of things, then unfortunately not. Copying the module is the way to go; you'll need to change the names of all the functions so they don't collide with those in the core module, and change paths/cache keys/variables for the same reason.

share|improve this answer
I literally copied the forum module so as to change the URI from forum to forums so it's the forum_menu() I would overload -- with my custom module name but how then does Drupal know which menu path to use? – Alex.Barylski Feb 23 '14 at 23:46
If you just need to change a URL like that don't bother with a custom module, just add an alias from forums -> forum, that'll take care of it. hook_menu_alter() probably isn't appropriate for that, as links to the original path would need to be changed. You could always use hook_url_inbound_alter() for that, but for a path change an alias is much easier – Clive Feb 24 '14 at 0:18
I thought of that but the forum module uses the singular version when you have selected a topic under it -- which is the desired structure. So wouldn't that conflict? – Alex.Barylski Feb 24 '14 at 3:29
They shouldn't do - all core methods will use the l() function to link to the page, and that handles aliasing for you. So if you (or a core module) have a bit of code like this: print l('forum', 'Forum');, the href attribute on the <a> tag will be the alias (forums), not the original path (forum) – Clive Feb 24 '14 at 9:38
Ah sorry I didn't get what you meant, but I think you'll still be ok - the path for forum posts will be defined as something like forum/% so it "shouldn't" interfere :) – Clive Feb 24 '14 at 22:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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