function merci_delete_node_type_validate in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.module \merci_delete_node_type_validate()
- 7.2 merci.module \merci_delete_node_type_validate()
Validates deletion of node types.
Parameters
$type: The type being deleted.
1 call to merci_delete_node_type_validate()
- merci_form_alter in ./
merci.module - Implementation of hook_form_alter().
File
- ./
merci.module, line 1109 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_delete_node_type_validate(&$form) {
$type = $form['type']['#value'];
// Only validate active MERCI node types.
if (merci_is_merci_type($type)) {
//$settings = merci_load_item_settings($type);
$merci_type_setting = merci_type_setting($type);
// Determine CCK table and columns the date data is stored in.
$field = content_fields('field_merci_date');
$db_info = content_database_info($field);
$table = $db_info['table'];
// Join on nid here so that any version of the reservation that contain
// the bucket/resource is caught.
$reservations = db_query("SELECT ctn.nid, ctn.title FROM {" . $table . "} ct INNER JOIN {merci_reservation_detail} md ON ct.vid = md.vid INNER JOIN {node} ctn ON ct.nid = ctn.nid INNER JOIN {merci_{$merci_type_setting}_node} m ON md.merci_placeholder_nid = m.nid INNER JOIN {node} mn ON m.vid = mn.vid WHERE mn.type = '%s' AND m.merci_sub_type = %d ORDER BY ct.nid, ct.vid", $type, MERCI_SUB_TYPE_RESERVATION);
$bad_reservations = array();
while ($reservation = db_fetch_object($reservations)) {
$bad_reservations[$reservation->nid] = l($reservation->title, "node/{$reservation->nid}/edit", array(
'query' => drupal_get_destination(),
));
}
if (!empty($bad_reservations)) {
$name = node_get_types('name', $type);
drupal_set_message(t('@type can not be deleted because it is associated with the following reservations:', array(
'@type' => $name,
)) . theme('item_list', $bad_reservations), 'error');
unset($form['actions']['submit']);
}
}
}