Understanding drupal hook_nodeapi execution order
To solve a really ugly bug of the video module I had to track down, in a very detailed way, what was the hook execution order in the Drupal 5.x hook_nodeapi. Unfortunately I didn't found any detailed documentation of this neither on the handbooks nor in the developer documentation (on CVS).
This is why, armed with a lot of patience, I wrote down what happens at every content submission/previewing/loading.
Those are my results:
node submit (validation successfull):
prepare form validate submit insert
node submit (validation unsuccessfull):
prepare form validate
node/add/type (first visualization):
prepare form
node preview new node (validation unsuccessfull & successfull):
prepare form validate
node view:
load view
node edit:
load prepare form
node preview existing node:
load prepare form validate view
node submit existing node:
load prepare form validate submit update
UPDATE 1: Posted a feature request to the documentation team to insert this informations somewhere in Drupal documentation.
UPDATE 2: Please note that the form operation above is not available on the hook_nodeapi. It's just mean that the form is being constructed at that time. If you need to interact with the form (eg: adding/modifying form fields) you can do it using the hook_form_alter
- fabio's blog
- 2092 reads

The answer has to my
The answer has to my previous post has to do with Drupal module weights: http://drupal.org/node/110238.
hook_nodeapi
Great post.
It would be even more interesting to know the order in which the nodeapi hooks are called. For instance, if I want to change $node->content['files'], which is inserted by the upload_nodeapi, how do I make sure that upload_nodeapi has already been called when mymodule_nodeapi is called?
Yes... this is a common
Yes... this is a common problem too. I also investigated on this.
The system database table holds informations about installed drupal modules. In this table there is a field called weight which provide a sort of execution priority between modules.
Unfortunately Drupal 5 doesn't provide any sort of api to modify a module weight so you will need to directly write sql queries in your .install files to alter the weight values of your modules.
If I remember correctly, if two modules have the same weight they are executed in alphabetical order: captcha.module is executed before video.module.
Hope this helps.
Post new comment