hook_node_delete

7 node.api.php hook_node_delete($node)
8 node.api.php hook_node_delete($node)

Respond to node deletion.

This hook is invoked from node_delete_multiple() after the type-specific hook_delete() has been invoked, but before hook_entity_delete and field_attach_delete() are called, and before the node is removed from the node table in the database.

Parameters

$node: The node that is being deleted.

Related topics

12 functions implement hook_node_delete()

File

modules/node/node.api.php, line 474
Hooks provided by the Node module.

Code

<?php
function hook_node_delete($node) {
  db_delete('mytable')
    ->condition('nid', $node->nid)
    ->execute();
}
?>

Comments

Possbile to stop deletion with this hook?

Is it possible to stop deletion of this hook? Say, by returning false?

I'm aware of the consequences of creating a "protected" node.

Unfortunately No

No, take a look at node_delete_multiple(). To cancel using this hook, you would essentially be stopping in the middle of deleting data. Even giving your module a light weight wouldn't get it to the front of the line, as the module defining the content type has its hook_delete() called first.

No hooks that provide an opportunity to cancel the operation are called before the deletion process starts. You could throw an exception that causes a db transaction rollback, but I strongly encourage against that.

Login or register to post comments