Skip to content

Instantly share code, notes, and snippets.

@ccamara
Created May 13, 2013 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/5566877 to your computer and use it in GitHub Desktop.
Save ccamara/5566877 to your computer and use it in GitHub Desktop.
Prevents nodes and/or comments to be deleted. #drupal #nodes
<?php
//stop deletion of nodes and comments
function MODULE_form_alter (&$form, &$form_state) {
//stop any node/comment deletions
if ((isset($form['operation']['#value']) && $form['operation']['#value'] == 'delete') || $form['#id'] == 'node-delete-confirm' || $form['#id'] == 'comment-confirm-delete') {
//set a message...
drupal_set_message('your message');
//stop people from being able to submit the delete form (and in turn stop the delete)
unset($form['actions']['submit']);
//set the "cancel" link text to something else
$form['actions']['cancel']['#title'] = t('Back to previous page');
}
//Stop the deletion of user accounts
if ($form['#id'] == 'user-multiple-cancel-confirm' || $form['#id'] == 'user-cancel-confirm-form') {
drupal_set_message(t('You are attempting to delete a user account. Users on this site cannnot be deleted, to disable this users account, please block the account. Users with blocked accounts will not be able to login.'), 'error');
unset($form['user_cancel_method']);
unset($form['user_cancel_confirm']);
unset($form['user_cancel_notify']);
unset($form['actions']['submit']);
$form['actions']['cancel']['#title'] = t('Back to previous page');
}
@ccamara
Copy link
Author

ccamara commented May 13, 2013

This snippet has been taken from here: http://drupal.org/node/506222 and authored by sebanthony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment