[development] Trying to understand hook_nodeapi() invocation sequence from node.module -- updated

Gabor Hojtsy gabor at hojtsy.hu
Sat Nov 26 21:48:19 UTC 2005


Also do a debug_backtrace() call on the extra logging line, and log that
one too, so that you see from where you get called. That singles out the
exact cause of the problem. This is surely a bug which should be fixed.

Goba

Syscrusher wrote:
> On Thursday 24 November 2005 11:20, Syscrusher wrote:
> 
>>Now, on initial entry into the edit form on node with $nid == 8, here is the
>>output of that drupal_set_message():
>>
>>nodeapi load 8
>>nodeapi load 8
>>nodeapi prepare 8
>>nodeapi form 8
>>
>>And on a "preview" of the node after editing, I see this:
>>
>>nodeapi load 8
>>nodeapi load 8
>>nodeapi prepare 8
>>nodeapi form 8
>>nodeapi validate 8
>>nodeapi view 8
>>nodeapi validate 8
>>
>>My question is, why is $op=='load' being always invoked twice, and why is
>>$op=='validate' being invoked twice for previews?
> 
> 
> After examining the code in node.module, I've found what I think is the
> cause of this behavior, but I'm still not sure why it's done this way.
> 
> At line 370, in function node_load(), we see the following:
> 
>   if ($node->nid) {
>     // Call the node specific callback (if any) and piggy-back the
>     // results to the node or overwrite some values.
>     if ($extra = node_invoke($node, 'load')) {
>       foreach ($extra as $key => $value) {
>         $node->$key = $value;
>       }
>     }
> 
>     if ($extra = node_invoke_nodeapi($node, 'load')) {
>       foreach ($extra as $key => $value) {
>         $node->$key = $value;
>       }
>     }
> 
> My module doesn't define a new node type, but just adds fields to
> existing types, so it doesn't define its own hook_load() function.
> Thus, the call to node_invoke($node, 'load') ends up calling node_load
> recursively, I think. Thus, the second recursion may be calling my
> module's hook_nodeapi() function again for each load.
> 
> I'd still be curious to understand better what's going on here.
> 
> Thanks for any comments.
> 
> Scott
> 



More information about the development mailing list