if there is two modules A and B and both have same user_login hook. so when i log in. out of A_user_login() and B_user_login() function which one called first.and how drupal decide execution order of these two function

up vote 30 down vote accepted

Hooks are called in order of

  1. Weight, which is defined per module in the database as {system.weight}. Lower weights come earlier in the calling process.
  2. Alphabetical, by module name.

By default, modules get assigned a weight of 0, so nearly all hooks in the system run in alphabetical order. Some modules will adjust this in their install hooks so they run earlier or later in the module_invoke_all function.

See also: Adjusting module weight: what are the risks and things to look out for?

By default a modules weight defines its place in line to execute a hook_* function.

You may alter the default ordering of the implementing modules with hook_module_implements_alter. A small example can be found in further reading of this blog tutorial.

From that blog post an example implementation is:

function mymodule_module_implements_alter(&$module_list, $context){
 if($context === "node_insert"){
 $temp = $module_list['mymodule'];
 // Removing the mymodule key/value
 // Adding the mymodule key value as the last member in the list
 $module_list['mymodule'] = $temp;

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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