[development] Hook ordering
drupal at mclewin.com
Thu Jan 4 06:13:06 UTC 2007
Karoly Negyesi wrote:
> I need to work on my reputation :)
I never bound your handle to your name. Ok, I know where that sandbox is.
>> 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?
> hook_load is not a real hook, it's a callback, because at any given time only one is called.
> hook_nodeapi is a hook, at any given time all implementations are called in order.
> For example, hook_form_alter. What happens when two modules try to be the first? Or the last for that matter?
I realize that, I was using hook and callback synonymously when I should
not have. Or rather Drupal is and I was sucked into the nomenclature. :)
My point still stands, don't deal with the 'first' or 'last' case in a
hook registry. I suggest that the registry only allow for 'before' and
'after', just as your sandbox code is authored. The module that 'owns'
the node type can declare callback_load() when it needs logic to be run
I recognize that there is confusion on hook_nodeapi() vs
_load()/_update()/etc. The really do look like they overlap when one
first sees them, but that difference of one being called on every single
node type vs. being only called on the module's node type is important.
Somewhere else in this thread it was suggested that hook_nodeapi() be
renamed to hook_node_alter(). That is a simple change that is in line
with the _alter() pattern that is spreading through the Drupal API. I
think it also stands to clear up some of the confusion between
_nodeapi(op=operator) vs hook#operator() callbacks.
Larry Garfield states that he cannot understand the infatuation with
fewer functions and more switch() statements. I agree with him. The
callbacks we know as hook_load()/hook_update()/hook_insert()/etc are
much more in line with object patterns.
What do you all think about changing hook_nodeapi() to hook_node_alter()
in Drupal 6?
More information about the development