function SimpletestResultsForm::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

core/modules/simpletest/src/Form/SimpletestResultsForm.php, line 119

Class

SimpletestResultsForm
Test results form for $test_id.

Namespace

Drupal\simpletest\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $test_id = NULL) {
  // Make sure there are test results to display and a re-run is not being
  // performed.
  $results = [];
  if (is_numeric($test_id) && !($results = $this->getResults($test_id))) {
    $this->messenger()
      ->addError($this->t('No test results to display.'));
    return $this->redirect('simpletest.test_form');
  }
  // Load all classes and include CSS.
  $form['#attached']['library'][] = 'simpletest/drupal.simpletest';
  // Add the results form.
  $filter = static::addResultForm($form, $results, $this->getStringTranslation());
  // Actions.
  $form['#action'] = Url::fromRoute('simpletest.result_form', [
    'test_id' => 're-run',
  ])->toString();
  $form['action'] = [
    '#type' => 'fieldset',
    '#title' => $this->t('Actions'),
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
    '#weight' => -11,
  ];
  $form['action']['filter'] = [
    '#type' => 'select',
    '#title' => 'Filter',
    '#options' => [
      'all' => $this->t('All (@count)', [
        '@count' => count($filter['pass']) + count($filter['fail']),
      ]),
      'pass' => $this->t('Pass (@count)', [
        '@count' => count($filter['pass']),
      ]),
      'fail' => $this->t('Fail (@count)', [
        '@count' => count($filter['fail']),
      ]),
    ],
  ];
  $form['action']['filter']['#default_value'] = $filter['fail'] ? 'fail' : 'all';
  // Categorized test classes for to be used with selected filter value.
  $form['action']['filter_pass'] = [
    '#type' => 'hidden',
    '#default_value' => implode(',', $filter['pass']),
  ];
  $form['action']['filter_fail'] = [
    '#type' => 'hidden',
    '#default_value' => implode(',', $filter['fail']),
  ];
  $form['action']['op'] = [
    '#type' => 'submit',
    '#value' => $this->t('Run tests'),
  ];
  $form['action']['return'] = [
    '#type' => 'link',
    '#title' => $this->t('Return to list'),
    '#url' => Url::fromRoute('simpletest.test_form'),
  ];
  if (is_numeric($test_id)) {
    $this->cleaner
      ->cleanResultsTable($test_id);
  }
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.