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

Syscrusher scott at 4th.com
Fri Nov 25 02:37:40 UTC 2005


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

-- 
-------------------------------------------------------------------------------
Scott Courtney     Drupal user name: "syscrusher"   http://drupal.org/user/9184
scott at 4th dot com       Drupal projects: http://drupal.org/project/user/9184
Sandbox:  http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/syscrusher


More information about the development mailing list