You are here

public function RevisionOverviewForm::validateForm in Diff 8

Form validation 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 FormBase::validateForm

File

src/Form/RevisionOverviewForm.php, line 369

Class

RevisionOverviewForm
Provides a form for revision overview page.

Namespace

Drupal\diff\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $input = $form_state
    ->getUserInput();
  if (count($form_state
    ->getValue('node_revisions_table')) <= 1) {
    $form_state
      ->setErrorByName('node_revisions_table', $this
      ->t('Multiple revisions are needed for comparison.'));
  }
  elseif (!isset($input['radios_left']) || !isset($input['radios_right'])) {
    $form_state
      ->setErrorByName('node_revisions_table', $this
      ->t('Select two revisions to compare.'));
  }
  elseif ($input['radios_left'] == $input['radios_right']) {

    // @todo Radio-boxes selection resets if there are errors.
    $form_state
      ->setErrorByName('node_revisions_table', $this
      ->t('Select different revisions to compare.'));
  }
}