You are here

public function BatchExampleForm::submitForm in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/batch_example/src/Form/BatchExampleForm.php \Drupal\batch_example\Form\BatchExampleForm::submitForm()

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

batch_example/src/Form/BatchExampleForm.php, line 49

Class

BatchExampleForm
Form with examples on how to use cache.

Namespace

Drupal\batch_example\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Gather our form value.
  $value = $form_state
    ->getValues()['batch'];

  // Set the batch, using convenience methods.
  $batch = [];
  switch ($value) {
    case 'batch_1':
      $batch = $this
        ->generateBatch1();
      break;
    case 'batch_2':
      $batch = $this
        ->generateBatch2();
      break;
  }
  batch_set($batch);
}