hook_node_load

Versions
7
hook_node_load($nodes, $types)

Act on node objects when loaded.

This hook allows you to add information to node objects when loaded from the database. It takes an array of nodes indexed by nid as its first parameter. For performance reasons, information for all available nodes should be loaded in a single query where possible.

The types of all nodes being passed in are also available in the $types parameter. If your module keeps track of the node types it supports, this allows for an early return if nothing needs to be done.

Due to the internal cache in node_load_multiple(), you should not use this hook to modify information returned from the {node} table itself, since this may affect the way nodes are returned from the cache in subsequent calls to the function.

See also

comment_node_load()

@see taxonomy_node_load()

See also

forum_node_load()

Parameters

$nodes An array of node objects indexed by nid.

$types An array containing the types of the nodes.

Related topics

Code

modules/node/node.api.php, line 343

<?php
function hook_node_load($nodes, $types) {
  $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
  foreach ($result as $record) {
    $nodes[$record->nid]->foo = $record->foo;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.