Drupal hook order

When working on the flash node I started out not really knowing exactly when the various hooks were fired off. It didn't seem to appear anywhere on the drupal site.

What I discovered, by annotating the whole module with watchdog('where', '_function'); lines is that...

When you view a node you get: _load > _view

When you create a new node: _validate > _form

When you preview it, but there are errors: _validate > _form

When you preview it and it is ok: _validate > _view > _form

When you submit a new node: _validate > _insert > _load > _view

When you open a node for editing: _load > _validate > _form

When you submit your changes: _load > _validate > _update > _load > _view

When you delete a node: _load > _delete

If a form_set_error($name, $message) is issued during validation then the form is marked up with the errors and returned but no content is displayed.

You can also use $_POST['op'] to determine where you are in the edit cycle. If empty you are viewing, but it changes to Preview and then Submit (note capital letters!) depending on which button the user clicks.

Comments

Thanks!

You don't know (well, you do) how difficult is to find this information on the Drupal website and on Internet. It's hard to create a new module without knowing how the Drupal cycle works, your effort has saved a lot of my time. Thanks!

This needs to be updated though!

This sequence is probably out of date now - I think this was the one that applied in Drupal 4.7!