You are here

function uc_coupon_purchase_form_uc_coupon_add_form_alter in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 6 uc_coupon_purchase/uc_coupon_purchase.module \uc_coupon_purchase_form_uc_coupon_add_form_alter()
  2. 7.2 uc_coupon_purchase/uc_coupon_purchase.module \uc_coupon_purchase_form_uc_coupon_add_form_alter()

Implements hook_form_FORM_ID_alter() for uc_coupon_add_form().

Modify the coupon add form to include coupon purchase options.

File

uc_coupon_purchase/uc_coupon_purchase.module, line 277

Code

function uc_coupon_purchase_form_uc_coupon_add_form_alter(&$form) {
  $value = isset($form['#uc_coupon']) ? $form['#uc_coupon'] : new stdClass();
  $form['uc_coupon_purchase'] = array(
    '#type' => 'fieldset',
    '#title' => t('Coupon purchase options'),
    '#description' => t('These settings alter the generation of purchased coupons based on this coupon.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -1,
  );
  $form['uc_coupon_purchase']['purchase_suffix_length'] = array(
    '#type' => 'select',
    '#title' => t('Purchased coupon code suffix length'),
    '#default_value' => isset($value->data['purchase_suffix_length']) ? $value->data['purchase_suffix_length'] : 12,
    '#description' => t('A random string of at least this many characters will be appended to the base coupon code to ensure uniqueness.'),
    '#options' => drupal_map_assoc(range(4, 30)),
  );
  $form['uc_coupon_purchase']['purchase_relative'] = array(
    '#type' => 'checkbox',
    '#title' => t('Alter coupon date restrictions relative to the purchase date.'),
    '#description' => t('Checking this box will make purchased coupons valid for the same time span as the base coupon, otherwise coupons will always be valid between the same dates.'),
    '#default_value' => isset($value->data['purchase_relative']) ? $value->data['purchase_relative'] : FALSE,
  );
  $form['status']['#description'] .= '<br />' . t('Only inactive coupons can be selected as the base for a purchased coupon, subsequent purchased coupons will automatically be activated.');
  $form['#validate'][] = 'uc_coupon_purchase_uc_coupon_add_form_validate';
  $form['#entity_builders'][] = 'uc_coupon_purchase_build_coupon';
}