public function CouponGenerateForm::buildForm in Commerce Core 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
promotion/ src/ Form/ CouponGenerateForm.php, line 79
Class
- CouponGenerateForm
- Provides a form for bulk generating coupons.
Namespace
Drupal\commerce_promotion\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['quantity'] = [
'#type' => 'number',
'#title' => $this
->t('Number of coupons'),
'#required' => TRUE,
'#default_value' => '10',
'#min' => 1,
'#max' => 1000,
'#step' => 1,
];
$form['pattern'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Coupon code pattern'),
];
$form['pattern']['format'] = [
'#type' => 'select',
'#title' => $this
->t('Format'),
'#required' => TRUE,
'#options' => [
'alphanumeric' => $this
->t('Alphanumeric'),
'alphabetic' => $this
->t('Alphabetic'),
'numeric' => $this
->t('Numeric'),
],
'#default_value' => 'alphanumeric',
];
$form['pattern']['prefix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Prefix'),
'#size' => 20,
];
$form['pattern']['suffix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Suffix'),
'#size' => 20,
];
$form['pattern']['length'] = [
'#type' => 'number',
'#title' => $this
->t('Length'),
'#description' => $this
->t('Length does not include prefix/suffix.'),
'#required' => TRUE,
'#default_value' => 8,
'#min' => 1,
];
$form['limit'] = [
'#type' => 'radios',
'#title' => $this
->t('Number of uses per coupon'),
'#options' => [
0 => $this
->t('Unlimited'),
1 => $this
->t('Limited number of uses'),
],
'#default_value' => 1,
];
$form['usage_limit'] = [
'#type' => 'number',
'#title' => $this
->t('Number of uses'),
'#title_display' => 'invisible',
'#default_value' => 1,
'#min' => 1,
'#states' => [
'invisible' => [
':input[name="limit"]' => [
'value' => 0,
],
],
],
];
$form['limit_customer'] = [
'#type' => 'radios',
'#title' => $this
->t('Number of uses per customer per coupon'),
'#options' => [
0 => $this
->t('Unlimited'),
1 => $this
->t('Limited number of uses'),
],
'#default_value' => 1,
];
$form['usage_limit_customer'] = [
'#type' => 'number',
'#title' => $this
->t('Number of uses per customer'),
'#title_display' => 'invisible',
'#default_value' => 1,
'#min' => 1,
'#states' => [
'invisible' => [
':input[name="limit_customer"]' => [
'value' => 0,
],
],
],
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Generate'),
'#button_type' => 'primary',
];
return $form;
}