I'm sure this issue has been discussed before. Here's one link I found regarding it: http://www.ventanazul.com/webzine/articles/control-drupal-hooks-running-.... I actually see two features that would be nice here:
1) What the article discusses, which is allowing a module to be able to have a low weight for some hooks and a high weight for other hooks.
2) To allow a module to have its hook implementation invoked multiple times, at different weights, similar to what in other languages can be accomplished with "around" methods -- being able to do part of the processing before other modules and the remainder of the processing after other modules.
My proposed solution for this is for modules to be able to specify a hook_weights variable in the module's .info file. For example, some custom module could have the following in the .info file:
hook_weights[init][] = -10
hook_weights[nodeapi][] = -10
hook_weights[nodeapi][] = 10
This would give the module an effective weight of -10 for the init hook, effective weights of -10 and 10 for the nodeapi hook (meaning it would get called twice for each nodeapi invocation), and use the module's weight for all other hooks.
Right after submitting this issue, I'll post a patch for it (I want to include the issue number in the patch filename). I hope this is able to make it into Drupal 6 before development on 6 gets locked down.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | core-module_implements-195275-0.patch | 3.14 KB | effulgentsia |
Comments
Comment #1
effulgentsia commentedI attached a patch, implementing this.
Comment #2
moshe weitzman commentedAlso see code by chx: http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/chx/weights.... Something like this would be nice.
Comment #3
chx commentedComment #4
lilou commentedPatch cannot be applied to CVS HEAD.
Comment #5
effulgentsia commentedComment #6
scor commentedsubscribe. This could have been useful for the MODULE_preprocess_HOOK() implementations in the rdf module, but it's too late for D7 now...
Comment #7
effulgentsia commented#692950: Use hook_module_implements_alter to allow modules to alter the weight of hooks in module_implements is better.