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.

Comments

effulgentsia’s picture

Assigned: effulgentsia » Unassigned
Status: Active » Needs review
StatusFileSize
new3.14 KB

I attached a patch, implementing this.

moshe weitzman’s picture

Also see code by chx: http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/chx/weights.... Something like this would be nice.

chx’s picture

Version: 6.x-dev » 7.x-dev
lilou’s picture

Status: Needs review » Needs work

Patch cannot be applied to CVS HEAD.

effulgentsia’s picture

Version: 7.x-dev » 8.x-dev
scor’s picture

subscribe. This could have been useful for the MODULE_preprocess_HOOK() implementations in the rdf module, but it's too late for D7 now...

effulgentsia’s picture