function hook_load

Act on nodes being loaded from the database.

This hook is invoked only on the module that defines the node's content type (use hook_node_load() to respond to all node loads).

This hook is invoked during node loading, which is handled by entity_load(), via classes Drupal\node\NodeStorageController and Drupal\Core\Entity\DatabaseStorageController. 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

84 functions implement hook_load()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_category_load in drupal/core/modules/aggregator/aggregator.module
Loads an aggregator category.
aggregator_feed_load in drupal/core/modules/aggregator/aggregator.module
Loads an aggregator feed.
block_load in drupal/core/modules/block/block.module
Loads a block instance.
book_link_load in drupal/core/modules/book/book.module
Gets a book menu link by its menu link ID.
book_menu_link_load in drupal/core/modules/book/book.module
Implements hook_TYPE_load().

... See full list

File

drupal/core/modules/node/node.api.php, line 1191
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;
  }
}