[development] Hook ordering

Scott McLewin drupal at mclewin.com
Wed Jan 3 22:52:45 UTC 2007


Karoly Negyesi wrote:
> In Drupal 6 I would like to see a hook registry -- mostly 
> autodiscovered, but if you want ordering, then you can say "my 
> implementation of hook_nodeapi is to be run before module 
> this,that,foor,bar". Available in my sandbox,
I don't know which sandbox is yours and didn't see 'knegyesi', 'negyesi' 
or 'karoly' under 
http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/.  So, 
without looking at the code...

I've found more of a need to say 'this hook must run after module 
this,that,foo,bar'.  I figure you were not actually implying that the 
two ordering options were going to be limited to 'before' and 'first', 
but I didn't want to leave the open assumption.  Overall the registry 
would be helpful.  I've encountered a number of cases where I needed to 
make sure one of my hooks ran after the hooks for other modules, and 
hacking the system weight is only something I'll do as a last resort and 
for a module that won't leave a deployment that I manage.

>
> All nice and dandy. But, the next step would be to request for "I want 
> to be the first for hook_foo". What am I to do if two module asks for 
> this? Die a horrible death? Disable the offending modules? This code, 
> quite obviously will run on the modules page.
I agree that is a challenge, since the person who picked the 'first' 
ordering may not run with the particular module combination that an 
arbitrary site builder/admin will install.  I like the current pattern 
of hook_load() and friends as being 'first' for a module that defines 
its own type.  How about leaving that in place and only allowing 
'before' and 'after' designations in the proposed registry?

Scott




More information about the development mailing list