summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Hodgdon2012-09-25 18:24:35 (GMT)
committer Jennifer Hodgdon2012-09-25 18:24:35 (GMT)
commit06271db913ae5a49ea2f14c61259134e52dfa294 (patch)
tree1d2dba629bf05fca998a8becfe1ec7aa3ffc03fa
parentb1536cf0318de9a542ce8a928fe8ac449572a7e6 (diff)
Issue #1186886 by Albert Volkman, Mile23: Fix up docs for hook_node_load
-rw-r--r--modules/node/node.api.php37
1 files changed, 20 insertions, 17 deletions
diff --git a/modules/node/node.api.php b/modules/node/node.api.php
index 6d14a07..8719457 100644
--- a/modules/node/node.api.php
+++ b/modules/node/node.api.php
@@ -517,40 +517,43 @@ function hook_node_insert($node) {
}
/**
- * Act on nodes being loaded from the database.
+ * Act on arbitrary nodes being loaded from the database.
+ *
+ * This hook should 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.
*
* 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()
+ * invoked on the node's content type module, then field_attach_load_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.
- *
- * The $types parameter allows for your module to have an early return (for
- * efficiency) if your module only supports certain node types. However, if your
- * module defines a content type, you can use hook_load() to respond to loading
- * of just that content type.
- *
* @param $nodes
* An array of the nodes being loaded, keyed by nid.
* @param $types
- * An array containing the types of the nodes.
+ * An array containing the node types present in $nodes. Allows for an early
+ * return for modules that only support certain node types. However, if your
+ * module defines a content type, you can use hook_load() to respond to
+ * loading of just that content type.
*
* For a detailed usage example, see nodeapi_example.module.
*
* @ingroup node_api_hooks
*/
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;
+ // Decide whether any of $types are relevant to our purposes.
+ if (count(array_intersect($types_we_want_to_process, $types))) {
+ // Gather our extra data for each of these nodes.
+ $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
+ // Add our extra data to the node objects.
+ foreach ($result as $record) {
+ $nodes[$record->nid]->foo = $record->foo;
+ }
}
}