Manish Basdeo
Manish Basdeo

Reputation: 6269

How can i create my own hook in drupal6?

How does drupal create its own hook. Similarly i want a customized hook for myself. How am I to proceed ?

Upvotes: 2

Views: 151

Answers (2)

Bill Maloney
Bill Maloney

Reputation: 186

If you have a hook that passes a parameter by reference, and you can not use drupal_alter (for example a presave hook that passes in more than one argument) you can use module_implements.

This way a module could implement it as modulename_foo_presave instead of modulename_presave_alter. It is good for when you you want to let modules alter something at multiple points in its life cycle.

For an example in drupal core checkout the code for the node_validate (drupal 7).

foreach (module_implements('node_validate') as $module) {
  $function = $module . '_node_validate';
  $function($node, $form, $form_state);
}

from http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_validate/7

The same approach works in Drupal 6 if you want to create hook that can be implemented in this way.

Upvotes: 0

Naveed
Naveed

Reputation: 42093

May be you are looking for module_invoke_all

Some useful links to start with:

Upvotes: 2

Related Questions