function commerce_coupon_delete_form in Commerce Coupon 7.2
Form callback: coupon delete confirmation form.
1 string reference to 'commerce_coupon_delete_form'
- commerce_coupon_coupon_delete_form_wrapper in ./
commerce_coupon.module - Page wrapper: coupon delete confirmation form.
File
- includes/
commerce_coupon.admin.inc, line 176 - Administrative forms and callbacks for Commerce Coupon.
Code
function commerce_coupon_delete_form($form, &$form_state, $coupon) {
$form_state['commerce_coupon'] = $coupon;
// Ensure this include file is loaded when the form is rebuilt from the cache.
$form_state['build_info']['files']['form'] = drupal_get_path('module', 'commerce_coupon') . '/includes/commerce_coupon.admin.inc';
$form['#submit'][] = 'commerce_coupon_delete_form_submit';
$form = confirm_form($form, t('Are you sure you want to delete the coupon with code %code?', array(
'%code' => $coupon->code,
)), 'admin/commerce/coupons', '<p>' . t('Deleting this coupon cannot be undone.') . '</p>', t('Delete'), t('Cancel'), 'confirm');
// Get the orders referenced by the coupon.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_order')
->fieldCondition('commerce_coupons', 'target_id', $coupon->coupon_id);
$result = $query
->execute();
if (!empty($result)) {
$description = t('This coupon is referenced by an order and therefore cannot be deleted. Disable it instead.');
$form['description']['#markup'] .= '<p>' . $description . '</p>';
$form['actions']['submit']['#disabled'] = TRUE;
}
return $form;
}