Community & Support

How to prevent node deletion (cancel delete)

Hi,
I have a module with several custom node types that can be referenced to each other via nid. How can I prevent deletion of a node that is currently being referenced by another? I tried hook_delete() and hook_nodapi() but was only able to detect the dependency and to warn the user about it. I could use hook_access() for this but would then not be able to change the error message, right?
Thanks in advance for your hints.
Best regards,
Björn

Comments

which error message do you

which error message do you mean? i think you can still use hook_access() and set a drupal_set_message in your hook and return FALSE. but the next problem is, you should find which hook_access() called and return a page / an error message.

I mean the default 'Access

I mean the default 'Access denied' message that is shown when hook_access() returns FALSE. Which one is called should be under my control as it's a custom node type. I'll give it a try. Thanks for your reply.

Edit: I tried hook_access() and it worked...kind of. The hook is obviously fired for each $op value even when editing the node so my error message would pop up before trying to delete a node. The latter is also not be possible because when hook_access() returns FALSE for $op == 'delete' the delete button would not be rendered.

Another solution

I accomplished this by using hook_form_alter to intercept the deletion confirmation form and replace it's message and submit button with a message saying that the node could not be deleted. Then I just wrapped this in the logic to limit it's application. In my case a specific set of nodes.

nobody click here