You are here

function uc_coupon_table in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 7.2 uc_coupon.module \uc_coupon_table()

Create a tapir table of validated coupons with a "Remove" button for each.

Parameters

$coupons: An array of coupon options of the form code => title

$submit: An array of additional options to attach to the form's submit elements (e.g. #ajax, #submit)

1 string reference to 'uc_coupon_table'
uc_coupon_form in ./uc_coupon.module
Form builder for the uc_coupon form.

File

./uc_coupon.module, line 1236
Provides discount codes and gift certificates for Ubercart.

Code

function uc_coupon_table($coupons, $submit = FALSE) {
  $table = array(
    '#type' => 'tapir_table',
  );
  $table['#columns'] = array(
    'title' => array(
      'cell' => t('Active coupons'),
      'weight' => 0,
    ),
    'remove' => array(
      'cell' => t('Remove'),
      'weight' => 1,
    ),
  );
  $i = 0;
  foreach ($coupons as $code => $title) {
    $table[$i] = array(
      'title' => array(
        '#markup' => $title,
      ),
      'remove' => array(
        '#type' => 'submit',
        '#value' => t('Remove'),
        '#name' => 'uc-coupon-remove-' . $code,
      ),
    );
    if ($submit) {

      // Add ajax functionality to this table.
      $table[$i]['remove'] += $submit;
    }
    $i++;
  }
  return $table;
}