You are here

public function BatchExampleForm::buildForm 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::buildForm()

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

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

Class

BatchExampleForm
Form with examples on how to use cache.

Namespace

Drupal\batch_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['description'] = [
    '#type' => 'markup',
    '#markup' => $this
      ->t('This example offers two different batches. The first does 1000 identical operations, each completed in on run; the second does 20 operations, but each takes more than one run to operate if there are more than 5 nodes.'),
  ];
  $form['batch'] = [
    '#type' => 'select',
    '#title' => 'Choose batch',
    '#options' => [
      'batch_1' => $this
        ->t('batch 1 - 1000 operations'),
      'batch_2' => $this
        ->t('batch 2 - 20 operations.'),
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Go',
  ];
  return $form;
}