I have two custom modules well just call them one and two for now, both have a hook onto hook_node_insert(). However, module two also has a hook into module one that is initiated by it's hook to node_insert(). So here is what the code would look like:

one_node_insert($node) {
    //some code here
    module_invoke_all('one_complete', $node);

two_node_insert($node) {
    //some code here
two_one_complete($node) {
    //some different code here

What order do the hooks get called if the weight for module two is 0 and the weight for module one is -1? Logically I would think the order would be:

one_node_insert->two_one_complete-> two_node_insert

But from just a little bit of testing it seems to be


So my question is does drupal some how run hooks in levels? In other words does it run all functions directly hooked to node_insert before it continues down the line of other hooks?

  • No, module_invoke_all() runs to its full conclusion every time it's called, there's no waiting until an earlier invocation of the same has completed. It's a totally linear process, if that makes sense. Maybe you could outline your debugging methods? I think it's more likely those are giving false results. Logically speaking, if the one module's hook_node_insert() implementation is running first, then the order should be exactly what you expect. Is it possible two_node_insert is actually firing first and skewing your results? – Clive Oct 8 '13 at 21:30
  • If that is the case then the weight on the module isn't working correctly. I'll add some debuging code to see if that is the case though. Just wondering is the module weight stored somewhere in cache possibly? – Pitchinnate Oct 8 '13 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.