2

I want to customize my menu by using hook_menu_alter by over-writing another installed module, which also has a hook_menu_alter inside.

I check the procedure using xdebug, finding that drupal execute my hook_menu_alter first, and then the existing hook_menu_alter in that module. In this case all my alteration is being over-written. How can I reverse the order of execution?

Thanks!

3

You can try to change the weight of the module in the systems table but doesn't always work and can cause other issues. I would use the hook_modules_implement_alter function. You will need to unset yours and then add yours to the top or before the other module. Here is an example I used doing a hook_user_delete and hook_user_insert

function users_module_implements_alter(&$implementations, $hook)
{
  if($hook == "user_insert" || $hook == "user_delete")
  {
    unset($implementations['user']);
    $user = array('users' => false);
    $implementations = $user + $implementations;
  }
}

Yours would be like this:

function users_module_implements_alter(&$implementations, $hook)
{
  if($hook == "menu_alter")
  {
    unset($implementations['mymodule']);
    $mymodule = array('mymodule' => false);
    $implementations = $mymodule + $implementations; // Also could use array_merge
  }
}
  • Thank you! hook_modules_implement_alter works great. But I do it slightly different. Since I want my module to over write other module, the last line is "$implementations = $implementations + $mymodule;" – jack2684 Apr 6 '14 at 13:07
  • 1
    Remember to make a note of that somewhere it'll be easily found, or someone will get really frustrated while trying to figure out why some hook implementations do not get called. ;) – TwoD Apr 8 '14 at 8:23

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.