Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 424
w00d Avatar asked Aug 20 '10 15:08

w00d


2 Answers

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.

like image 190
Grayside Avatar answered Sep 29 '22 13:09

Grayside


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.

like image 45
apaderno Avatar answered Sep 29 '22 12:09

apaderno