public function CouponGenerateForm::submitForm in Commerce Core 8.2
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/
promotion/ src/ Form/ CouponGenerateForm.php, line 201
Class
- CouponGenerateForm
- Provides a form for bulk generating coupons.
Namespace
Drupal\commerce_promotion\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$quantity = $values['quantity'];
$coupon_values = [
'promotion_id' => $this->promotion
->id(),
'usage_limit' => $values['limit'] ? $values['usage_limit'] : 0,
'usage_limit_customer' => $values['usage_limit_customer'],
];
$pattern = new CouponCodePattern($values['format'], $values['prefix'], $values['suffix'], $values['length']);
$batch_builder = (new BatchBuilder())
->setTitle($this
->t('Generating coupons'))
->setProgressMessage('')
->setFinishCallback([
$this,
'finishBatch',
])
->addOperation([
get_class($this),
'processBatch',
], [
$quantity,
$coupon_values,
$pattern,
]);
batch_set($batch_builder
->toArray());
$form_state
->setRedirect('entity.commerce_promotion_coupon.collection', [
'commerce_promotion' => $this->promotion
->id(),
]);
}