Creating Drupal Module – Part 2
- April 6th, 2010
- Posted in Drupal
- Write comment
now I will cover the mymodule.module part
there is three hooks we use alot in backend those are
insert_hook, update_hook, delete_hook
each hook add node, delete node, and update node
insert_hook
starting clear we can implement hook insert by name modulename_insert
function modulename_insert($node) { db_query("INSERT INTO {mytable} (nid, extra) VALUES (%d, '%s')", $node->nid, $node->extra); }function modulename_update($node) { //if the node is set for revision insert instead of deleteif ($node->revision) { modulename_insert($node); } else{ db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d", $node->extra, $node->nid); } }function modulename_delete(&$node) { db_query('DELETE FROM {mytable} WHERE nid = %d', $node->nid); }
No comments yet.