开发者

Difference between hook_node_type() and hook_nodeapi()

开发者 https://www.devze.com 2023-01-11 11:31 出处:网络
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.

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_n开发者_JS百科ode_story($op, $info){
   dsm($info);
}


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':
      ...
    }
  }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号