You are here

function merci_node_admin_delete_validate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6

Same name and namespace in other branches
  1. 6.2 includes/api.inc \merci_node_admin_delete_validate()
  2. 7.2 includes/api.inc \merci_node_admin_delete_validate()

Custom validation function to protect merci nodes from mass deletion.

1 string reference to 'merci_node_admin_delete_validate'
merci_form_alter in ./merci.module
Implementation of hook_form_alter().

File

./merci.module, line 2658
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_node_admin_delete_validate($form, &$form_state) {

  // Look only for delete op.
  $operation = $form_state['values']['operation'];
  if ($operation != 'delete') {
    return;
  }

  // Get the checked nodes.
  $nids = array_filter($form_state['values']['nodes']);

  // Perform the check for each submitted node.
  foreach ($nids as $nid) {
    $node = node_load($nid);

    // Check to see if any of the nodes should not be deleted.
    if (!merci_delete_item_validate($node, FALSE)) {

      // If so, then unset the checked node so it will not be processed, and display a warning.
      // Note that the array element has to be completely removed here in order to prevent the
      // node from being deleted, due to the nature of the mass deletion callback.
      unset($form_state['values']['nodes'][$nid]);
      unset($nids[$nid]);
    }
  }

  // If we've unset all of the nodes that were checked, then don't continue with the form processing.
  if (!count($nids)) {
    drupal_set_message('No nodes selected.', 'error');
    drupal_goto('admin/content/node');
  }
}