function hook_load

hook_load($nodes)

Act on nodes being loaded from the database.

This is a node-type-specific hook, which is invoked only for the node type being affected. See Node API hooks for more information.

Use hook_node_load() to respond to node load of all node types.

This hook is invoked during node loading, which is handled by entity_load(), via classes NodeController and DrupalDefaultEntityController. After the node information is read from the database or the entity cache, hook_load() is invoked on the node's content type module, then field_attach_node_revision() or field_attach_load() is called, then hook_entity_load() is invoked on all implementing modules, and finally hook_node_load() is invoked on all implementing modules.

This hook should only be used to add information that is not in the node or node revisions table, not to replace information that is in these tables (which could interfere with the entity cache). For performance reasons, information for all available nodes should be loaded in a single query where possible.

Parameters

$nodes: An array of the nodes being loaded, keyed by nid.

For a detailed usage example, see node_example.module.

Related topics

File

modules/node/node.api.php, line 1211
Hooks provided by the Node module.

Code

function hook_load($nodes) {
  $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;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_load/7.x