hook_nodeapi() in Drupal 6 became (see Node API page) hook_node_delete(), hook_node_insert(), hook_node_load(), hook_node_prepare(), hook_node_prepare_translation(), hook_node_search_result(), hook_node_presave(), hook_node_update(), hook_node_update_index(), hook_node_validate(), and hook_node_view() in Drupal 7.
Example in Drupal 6 :
/**
* Implements hook_nodeapi().
*/
function hook_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'load':
// Load a book.
}
}
Example in Drupal 7 :
/**
* Implements hook_node_load().
*/
function hook_node_load($nodes, $types) {
// Load a book.
}
/**
* Implements hook_node_update().
*/
function hook_node_update($node) {
db_update('mytable')
->fields(array('extra' => $node->extra))
->condition('nid', $node->nid)
->execute();
}
/**
* Implements hook_node_insert().
*/
function hook_node_insert($node) {
db_insert('mytable')
->fields(array(
'nid' => $node->nid,
'extra' => $node->extra,
))
->execute();
}
Example in Drupal 6 :
/**
* Implements hook_nodeapi().
*/
function hook_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'load':
// Load a book.
}
}
Example in Drupal 7 :
/**
* Implements hook_node_load().
*/
function hook_node_load($nodes, $types) {
// Load a book.
}
/**
* Implements hook_node_update().
*/
function hook_node_update($node) {
db_update('mytable')
->fields(array('extra' => $node->extra))
->condition('nid', $node->nid)
->execute();
}
/**
* Implements hook_node_insert().
*/
function hook_node_insert($node) {
db_insert('mytable')
->fields(array(
'nid' => $node->nid,
'extra' => $node->extra,
))
->execute();
}
can u give me clear example for hook_nodeapi in drupal for update..
ReplyDeleteThanks a lot..
Thank you, this is useful information.
ReplyDeleteBut case of "delete" ??
ReplyDeleteBut case of "delete" ?
ReplyDelete