views:

37

answers:

2

I'm trying to understand the difference between hook_node_type and hook_nodeapi

I've tried to use hook_node_type with the story node and a simple dsm but got nothing.

function mymod_node_story($op, $info){
   dsm($info);
}
+4  A: 

hook_node_type is made to hook into when a node type is changed. Fx if you want to allow comments on node type story etc.

hook_nodeapi is used to be able to hook into the different processes that can happen to an actual node, like when a node is saved, when it's being viewed etc.

There's not a hook for specific nodes, but instead you usually do something like this.

function module_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($node->type == 'story') {
    switch ($op) {
      case 'load':
      ...
    }
  }
}
googletorp
I see. Is there a hook that's identical to `hook_nodeapi` but targets only a specific node type? Something that would look like `hook_nodeapi_story` if it existed.
lok
@lok: No; Drupal core code uses only `hook_nodeapi()`.
kiamlaluno
+3  A: 

hook_node_type() is invoked each time a content type is deleted, or renamed. The purpose of the hook is to rename the Drupal variables used for the content type (which is automatically done for any form field included in the content type edit form, from node_type_form_submit()), or to delete the Drupal variables containing values for the content type that has been deleted.

hook_nodeapi() is invoked for each node when it's loaded from the database, the node edit form is shown, the node is visualized, when the node is being indexed from the search module, when a RSS feed, or the node is saved. A module should implement hook_nodeapi() to alter nodes for content types implemented by other modules.

kiamlaluno