function bat_unit_form_bat_type_bundle_operation_form_alter in Booking and Availability Management Tools for Drupal 7
Implements hook_form_FORM_ID_alter().
FORM_ID = bat_type_bundle_operation_form Prevent a Bat type bundle with associated unit bundles from being deleted.
File
- modules/
bat_unit/ bat_unit.module, line 1784
Code
function bat_unit_form_bat_type_bundle_operation_form_alter(&$form, &$form_state) {
// Check if types of a type bundle exist before allowing deletion.
if ($form_state['op'] == 'delete') {
$type_bundle = $form_state['bat_type_bundle'];
// Load the Bat Types associated with this bundle.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'bat_type')
->propertyCondition('type', $type_bundle->type);
$types = $query
->execute();
if (isset($types['bat_type']) && count($types['bat_type'])) {
// This type bundle has associated types, don't allow deletion.
form_set_error('confirm', t('This Bat Type bundle has associated Types. Please delete all Types before attempting to delete this Bat Type bundle.'));
unset($form['description']);
unset($form['actions']);
unset($form['confirm']);
}
}
}