You are here

public function PerfmonRunForm::submitForm in Performance monitor 8

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

src/Form/PerfmonRunForm.php, line 38

Class

PerfmonRunForm

Namespace

Drupal\perfmon\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $testlist = perfmon_get_testlist();

  // Use Batch to process the testlist.
  $batch = array(
    'operations' => array(),
    'title' => t('Performance test'),
    'progress_message' => t('Progress @current out of @total.'),
    'error_message' => t('An error occurred. Rerun the process or consult the logs.'),
    'finished' => '_perfmon_batch_finished',
  );
  $log = \Drupal::config('perfmon.settings')
    ->get('perfmon_log');
  foreach ($testlist as $test_name => $test) {

    // Each test is its own operation. There could be a case where a single
    // test needs to run itself a batch operation, perhaps @todo?
    $batch['operations'][] = array(
      '_perfmon_batch_op',
      array(
        $test_name,
        $test,
        $log,
      ),
    );
  }
  batch_set($batch);
}