views:

98

answers:

4

I'm writing a custom module, and I would like to do some checks before the node is deleted. Is there a hook that gets trigerred before a node is deleted? And is there a way to somehow prevent the deletion? BTW, I'm using drupal6

+1  A: 

You can use hook_nodeapi op delete.

It might be a bad idea trying to stop the deletion of a node, since you don't know what other modules have done, like deleting cck field values etc.

There is no hook you can use to do actions before a node is being deleted. The above is the closest you can come.

googletorp
The whole point is that I want access "before" any deletes happen on the node. I'm well aware of this hook, but doesn't help me as far as I can see
Ammar Ibrahim
A: 

There isn't a hook that gets called before the node gets deleted, but Drupal does check with node_access to see if the user is allowed to delete the node before continuing with the deletion.

You could set the node access permissions to not allow the user to delete the node: it won't help if the user is user 1 or has the administer nodes permission, so don't give those permissions to untrusted users (i.e. people who would delete a node). This is also the Drupal Way to prevent unwarranted node deletions.

Mark Trapp
+1  A: 

You can use hook_menu_alter to point the menu callback node/%node/delete to your own function. Your function can do whatever checks you want and then present the node_delete_confirm form if the checks pass.

kurreltheraven
It works for my case since it's a closed system, but there's a security flaw in it, but it doesn't matter for my case.
Ammar Ibrahim
A: 

you can use hook_access and put conditions if op == delete. if you conditions fullfilled return True otherwise return false. in case of false your node will not be deleted.

Remember for admin this will not be triggered.

zaheer