| Versionen | |
|---|---|
| drupal7 | 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.
$nodes An array of node objects indexed by nid.
$types An array containing the types of the nodes.
modules/
<?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;
}
}
?>
Kommentare
Kommentar hinzufügen