You are here

function uc_coupon_table in Ubercart Discount Coupons 7.2

Same name and namespace in other branches
  1. 7.3 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

$ajax: The #ajax array to apply to each remove button, or FALSE if the form is not ajax enabled.

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 1121

Code

function uc_coupon_table($coupons, $ajax = 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 ($ajax) {

      // Add ajax functionality to this table.
      $table[$i]['remove'] += array(
        '#ajax' => $ajax,
      );
    }
    $i++;
  }
  return $table;
}