Some questions about hooks are not obvious in the 5.0 API documentation so I made some notes that could be useful. The extra information is mostly about the sequence of hooks.

Here are the notes. If the API pages had comments, we could add the comments direct to the pages for later incorporation into the documentation after review.

http://api.drupal.org/api/HEAD/function/hook_load

Usage

hook_load is called by node.php in node_load to load the extra data your module adds to the node. node_load then calls the nodeapi hooks in all modules to give them a chance to modify the node. As an example, author.module creates nodes of type author and defines author_load to add web site information to author nodes. Any other module can then use hook_nodeapi to change the author nodes. The node is then available for viewing and updating.

hook_view is called after hook_load to modify the node for presentation during the themeing process. hook_load loads the data that goes into a node update form and back into the database. If data needs an extra modification just for display on a Web page then perform the extra modification in hook_view.

http://api.drupal.org/api/HEAD/function/hook_view

Usage

hook_view is called after hook_load and hook_nodeapi. hook_load adds additional data for a specific node type, nodeapi then lets any module modify the node and finally hook_view prepares the node for viewing. You could use hook_view to translate raw data inserted by another module.

Comments

betz’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Developer Guide » documentation

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443

betz’s picture

Project: Drupal core » Documentation
Version: 7.x-dev »
Component: documentation » Correction/Clarification
dawehner’s picture

i would add this to the node_example module, because there is for me a better place to look at for hook_node/hook_view

the documentation of the hook should be technical

jhodgdon’s picture

Project: Documentation » Drupal core
Version: » 5.0
Component: Correction/Clarification » documentation

This is API documentation. Moving back to the Drupal queue, as per #296364: Proposal: Move all api.drupal.org issues to the Drupal project.

jhodgdon’s picture

Title: hook_load and hook_view » hook_load and hook_view documentation needs more detail
Version: 5.0 » 7.x-dev
Category: feature » bug
Priority: Normal » Minor

If this is addressed, it should be done in 7.x (the documentation is substantially the same there) and then back-ported to 5.x/6.x.

tanoshimi’s picture

In fact, the hook_load documentation for 7.x-dev is inaccurate. The example given at http://api.drupal.org/api/function/node_example_load/7 makes use of the deprecated db_fetch_object syntax

jhodgdon’s picture

Status: Active » Fixed

These function docs were fixed up in another issue and I think they are fine now.

jhodgdon’s picture

As a note, this page also gives a full description of the node hooks: http://api.drupal.org/api/group/node_api_hooks/7

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

donquixote’s picture

"Node-type-specific hooks: These hooks are only invoked on the primary module, using the "base" return component of hook_node_info() as the function prefix. For example, poll.module defines the base for the Poll content type as "poll", so during creation of a poll node, hook_insert() is only invoked by calling poll_insert()."

This is not obvious from the documentation on these pages,
http://api.drupal.org/api/drupal/developer--hooks--node.php/function/hoo...
http://api.drupal.org/api/drupal/developer--hooks--node.php/function/hoo...
http://api.drupal.org/api/drupal/developer--hooks--node.php/function/hoo...

jhodgdon’s picture

donquixote: Did you want to reopen this issue? It is currently closed.

donquixote’s picture

Status: Closed (fixed) » Active

I thought I let other people decide.
But, makes sense to reopen, so others can decide to re-close :)

jhodgdon’s picture

Status: Active » Closed (duplicate)

The problem is that a closed issue does not show up in standard views of issues (such as the "Your Issues" page). So if you really want to re-open discussion on an issue, you need to make sure its status is not "Closed - (whatever)".

Regarding the comment above... I think it is clear now in the Drupal 7 documentation, but it hasn't been updated in the Drupal 6 docs yet. I think this is really a duplicate of #629518: hook_node_insert() and other node hooks have imprecise/misleading descriptions, which is still open for Drupal 6, and has two patches that need to be ported to Drupal 6.

donquixote’s picture

clear now in the Drupal 7 documentation

http://api.drupal.org/api/drupal/modules--node--node.api.php/function/ho...

Display a node.

This is a hook used by node modules. It allows a module to define a custom method of displaying its nodes, usually by displaying extra information particular to that node type.

Not clear enough, imo.
The important point is that this hook is only called for the node type declared by this module, in hook_node_info(). This needs to be highlighted, because it is not what you would expect from a hook.

donquixote’s picture

Status: Closed (duplicate) » Active

ehm..

jhodgdon’s picture

Status: Active » Closed (duplicate)

Please reopen that other issue for Drupal 7. This issue is a duplicate of the other issue.