Nodeapi load operation drupaldocs

Fool2 - October 12, 2005 - 18:01
Project:Documentation
Component:Developer Guide
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Under nodeapi in drupaldocs, the return value for the load operation is listed as "The "load" operation should return an object containing extra fields to be merged into the node object. "

http://drupaldocs.org/api/4.6/function/hook_nodeapi

However, when I return a value like so from a module:

case "load":
$obj = new stdclass;
$obj->foo = "bar";
return $obj;
break;

$node->foo is not defined when the node is loaded. Now, this means the doc either has to be more specific about how the object is merged, or is simply wrong.

The implementations I have seen (and the ones I have gotten to work myself) all are coded like so:

case "load":
$node->foo="bar";
break;

Anybody have any input on this confusion?

#1

Fool2 - October 12, 2005 - 20:36

Did some more research...

if ($extra = node_invoke_nodeapi($node, 'load')) {
    foreach ($extra as $key => $value) {
      $node->$key = $value;
    }
  }

I'm not sure what this means exactly... does it mean it will need an array?

Or does it mean that my variable would be registered as $node->obj->foo or $node->obj['foo']?

I'm sure a lot of less experienced people like me are running into this ambiguity.

#2

dado - October 12, 2005 - 20:44

Fool2,

I think the documentation is misleading here. I think the hook_nodeapi operation "load" does not need a return value. Rather, simply add the desired fields to the $node object, as you do here

case "load":
$node->foo="bar";
break;

dado

#3

pz - October 12, 2005 - 21:10

If I remember correctly there is an error in the docs regarding load for nodeapi, if you return an array instead of an object I think it works as documented.

#4

drewish - October 16, 2005 - 23:47

to second what pz said, i've had luck returning an array. (without actually researching it,) my recollection is that whatevery you return gets array_merged.

#5

chx - October 21, 2005 - 12:58
Priority:normal» critical

#6

chx - October 21, 2005 - 17:11
Priority:critical» normal

found a cvs capable server, fixed HEAD. Someone fix 4.6 plz

#7

sepeck - January 5, 2007 - 07:07
Status:active» closed
 
 

Drupal is a registered trademark of Dries Buytaert.