w00d
w00d

Reputation: 5596

hook_preprocess_node() execution order

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

Upvotes: 8

Views: 6365

Answers (2)

avpaderno
avpaderno

Reputation: 29709

If 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.

Upvotes: 2

Grayside
Grayside

Reputation: 4194

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.

Upvotes: 13

Related Questions