Community Documentation

hook_load

5 node.php hook_load($node)
6 node.php hook_load($node)
7 node.api.php hook_load($nodes)
8 node.api.php hook_load($nodes)

Load node-type-specific information.

This is a hook used by node modules. It is called to allow the module a chance to load extra information that it stores about a node, or possibly replace already loaded information - which can be dangerous.

Parameters

$node: The node being loaded. At call time, node.module has already loaded the basic information about the node, such as its node ID (nid), title, and body.

Return value

An object containing properties of the node being loaded. This will be merged with the passed-in $node to result in an object containing a set of properties resulting from adding the extra properties to the passed-in ones, and overwriting the passed-in ones with the extra properties if they have the same name as passed-in properties.

For a detailed usage example, see node_example.module.

Related topics

▾ 27 functions implement hook_load()

actions_load in includes/actions.inc
Retrieve a single action from the database.
aggregator_category_load in modules/aggregator/aggregator.module
Load an aggregator category.
aggregator_feed_items_load in modules/aggregator/aggregator.pages.inc
Load feed items by passing a SQL query.
aggregator_feed_load in modules/aggregator/aggregator.module
Load an aggregator feed.
book_link_load in modules/book/book.module
Like menu_link_load(), but adds additional data from the {book} table.
contact_load in modules/contact/contact.module
Load the data for a single contact category.
drupal_load in includes/bootstrap.inc
Includes a file with the provided type and name. This prevents including a theme, engine, module, etc., more than once.
file_download in includes/file.inc
Call modules that implement hook_file_download() to find out if a file is accessible and what headers it should be transferred with. If a module returns -1 drupal_access_denied() will be returned. If one or more modules returned headers the download…
file_save_upload in includes/file.inc
Saves a file upload to a new location.
filter_format_load in modules/filter/filter.module
forum_load in modules/forum/forum.module
Implementation of hook_load().
forum_term_load in modules/forum/forum.module
Fetch a forum term.
hook_file_download in developer/hooks/core.php
Control access to private file downloads and specify HTTP headers.
menu_link_load in includes/menu.inc
Get a menu link by its mlid, access checked and link translated for rendering.
menu_load in modules/menu/menu.module
Load the data for a single custom menu.
node_load in modules/node/node.module
Load a node object from the database.
path_load in modules/path/path.module
Fetch a specific URL alias from the database.
poll_load in modules/poll/poll.module
Implementation of hook_load().
taxonomy_vocabulary_load in modules/taxonomy/taxonomy.module
Return the vocabulary object matching a vocabulary ID.
upload_file_download in modules/upload/upload.module
Implementation of hook_file_download().
upload_load in modules/upload/upload.module
user_category_load in modules/user/user.module
Return a user object after checking if any profile category in the path exists.
user_external_load in modules/user/user.module
user_file_download in modules/user/user.module
Implementation of hook_file_download().
user_load in modules/user/user.module
Fetch a user object.
user_uid_optional_load in modules/user/user.module
Load either a specified or the current user account.
_comment_load in modules/comment/comment.module
Load the entire comment by cid.

File

developer/hooks/node.php, line 320
These hooks are defined by node modules, modules that define a new kind of node.

Code

<?php
function hook_load($node) {
  $additions = db_fetch_object(db_query('SELECT * FROM {mytable} WHERE vid = %d', $node->vid));
  return $additions;
}
?>

Comments

object merge

I experienced a problem with calling this function from a non-hook because I expected the returned object to contain all the properties of the node, and whatever else gets loaded in hook_load. Instead, as the API is worded, this function should only return new properties specific to your content module's node type. You may have to merge the $node and the object containing all your new properties returned by hook_load, to work with a complete node object.

use node_load?

@beefzilla - doesn't "node_load($nid)" do the merging for you?

Probably better to call node_load because that way you get extras from all the modules you've got installed?

Could be I'm not fully understanding the issue though! :-)

Login or register to post comments