You are here

public function SimpletestResultsForm::submitForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/Form/SimpletestResultsForm.php \Drupal\simpletest\Form\SimpletestResultsForm::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

core/modules/simpletest/src/Form/SimpletestResultsForm.php, line 178
Contains \Drupal\simpletest\Form\SimpletestResultsForm.

Class

SimpletestResultsForm
Test results form for $test_id.

Namespace

Drupal\simpletest\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $pass = $form_state
    ->getValue('filter_pass') ? explode(',', $form_state
    ->getValue('filter_pass')) : array();
  $fail = $form_state
    ->getValue('filter_fail') ? explode(',', $form_state
    ->getValue('filter_fail')) : array();
  if ($form_state
    ->getValue('filter') == 'all') {
    $classes = array_merge($pass, $fail);
  }
  elseif ($form_state
    ->getValue('filter') == 'pass') {
    $classes = $pass;
  }
  else {
    $classes = $fail;
  }
  if (!$classes) {
    $form_state
      ->setRedirect('simpletest.test_form');
    return;
  }
  $form_execute = array();
  $form_state_execute = new FormState();
  foreach ($classes as $class) {
    $form_state_execute
      ->setValue([
      'tests',
      $class,
    ], $class);
  }

  // Submit the simpletest test form to rerun the tests.
  // Under normal circumstances, a form object's submitForm() should never be
  // called directly, FormBuilder::submitForm() should be called instead.
  // However, it calls $form_state->setProgrammed(), which disables the Batch API.
  $simpletest_test_form = SimpletestTestForm::create(\Drupal::getContainer());
  $simpletest_test_form
    ->buildForm($form_execute, $form_state_execute);
  $simpletest_test_form
    ->submitForm($form_execute, $form_state_execute);
  if ($redirect = $form_state_execute
    ->getRedirect()) {
    $form_state
      ->setRedirectUrl($redirect);
  }
}