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
Comment #1
betz commentedChanged the component to reflect the new component categorization. See http://drupal.org/node/301443
Comment #2
betz commentedComment #3
dawehneri 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
Comment #4
jhodgdonThis is API documentation. Moving back to the Drupal queue, as per #296364: Proposal: Move all api.drupal.org issues to the Drupal project.
Comment #5
jhodgdonIf 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.
Comment #6
tanoshimi commentedIn 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
Comment #7
jhodgdonThese function docs were fixed up in another issue and I think they are fine now.
Comment #8
jhodgdonAs a note, this page also gives a full description of the node hooks: http://api.drupal.org/api/group/node_api_hooks/7
Comment #10
donquixote commented"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...
Comment #11
jhodgdondonquixote: Did you want to reopen this issue? It is currently closed.
Comment #12
donquixote commentedI thought I let other people decide.
But, makes sense to reopen, so others can decide to re-close :)
Comment #13
jhodgdonThe 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.
Comment #14
donquixote commentedhttp://api.drupal.org/api/drupal/modules--node--node.api.php/function/ho...
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.
Comment #15
donquixote commentedehm..
Comment #16
jhodgdonPlease reopen that other issue for Drupal 7. This issue is a duplicate of the other issue.