views:

77

answers:

2

If I have two modules, each has implemented its preprocess_node hook. Then which one will be called first ? Is there anyway to enforce the order in which it would be called ?

module1_preprocess_node(&$vars){
  $vars['submitted'] = "test1";
}

module2_preprocess_node(&$vars){
  $vars['submitted'] = "test2";
}

I wonder which would be the result... test1, or test2. Thanks in advance

+4  A: 

All hooks in Drupal are fired in module-weight order. By default, all module's have a weight of zero, so if you want to control the exact order they fire in, you need to change something in the database.

How to Update a Module's Weight

If you look at the API docs for module_list(), ties break in alphabetical order of the filename of the .module file.

Grayside
+1 for link to update module's weight
Mike Munroe
A: 

If neither the modules didn't change their weight in the table system, then the result will be test2.

The first module invoked is the one with a lighter weight; when two modules have the same weight, they are sorted by alphabetical ascending order. This is valid for every invoked hook.

kiamlaluno

related questions