April 16, 2013
Hooks in Drupal are awesome, but when another module calls the same hook it can cause conflicts (hook_form_alter is a common example). If you want to make sure your module's hooks get called last, you need to use hook_module_implements_alter(). Here's a code snippet for how to accomplish this:
/** * Implements hook_module_implements_alter(). */ function example_module_implements_alter(&$implementations, $hook) { if ($hook == 'hook_name') { // (e.g. form_alter, node_save, etc) $group = $implementations['example']; // 'example' is the name of your module unset($implementations['example']); $implementations['example'] = $group; } }
This will move your hook to the end of the list and get processed last... assuming of course that another module isn't also calling hook_module_implements_alter(). If it is, then you need to change the weight of your module. "How to update a module's weight" is a good resource for how to do this.