You are here

function commerce_coupon_form_commerce_discount_operation_form_alter in Commerce Coupon 7.2

Implements hook_form_FORM_ID_alter().

File

./commerce_coupon.module, line 260
Provides coupon functionality for Drupal Commerce.

Code

function commerce_coupon_form_commerce_discount_operation_form_alter(&$form, &$form_state) {
  if ($form_state['op'] == 'delete') {

    // See if there are any coupons referencing this discount.
    $discount_wrapper = entity_metadata_wrapper('commerce_discount', $form_state['commerce_discount']);
    if ($discount_wrapper->coupons
      ->count()) {
      $form['description']['#markup'] = t('This discount cannot be deleted because it has coupons referencing it. Try disabling it instead, or deleting the coupons first.');
      unset($form['actions']['submit']);
    }
  }
}