Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3253639
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3253639
Commits
b019bf1c
Commit
b019bf1c
authored
12 years ago
by
Jennifer Hodgdon
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1186886
by Albert Volkman, Mile23: Add detail and better example to hook_node_load docs
parent
8643c012
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/node/node.api.php
+20
-17
20 additions, 17 deletions
core/modules/node/node.api.php
with
20 additions
and
17 deletions
core/modules/node/node.api.php
+
20
−
17
View file @
b019bf1c
...
...
@@ -528,40 +528,43 @@ function hook_node_insert(Drupal\node\Node $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 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
* 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
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment