Understanding drupal hook_nodeapi execution order

Submitted by fabio on Thu, 2007-06-28 18:22.

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

Superb Information

Submitted by Gaurav Arya (not verified) on Mon, 2009-06-22 11:10.

Hey fabio, Thanks so much for this great information.

It would be even more

Submitted by wesley (not verified) on Sun, 2009-06-14 11:30.

It would be even more interesting to know the order in which the nodeapi hooks are called.rapidL

please re-read the post. It

Submitted by fabio on Tue, 2009-06-16 18:04.

please re-read the post. It contains exactly those informations.

The answer has to my

Submitted by Rareş (not verified) on Mon, 2008-06-30 00:23.

The answer has to my previous post has to do with Drupal module weights: http://drupal.org/node/110238.

hook_nodeapi

Submitted by Rareş (not verified) on Sun, 2008-06-29 22:18.

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

Submitted by fabio on Mon, 2008-06-30 11:07.

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

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <img> <h2> <h3> <h4> <b>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.

More information about formatting options

4 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.