You are here

public function ConfigForm::validateForm in JSON Web Token Authentication (JWT) 8

Same name and namespace in other branches
  1. 8.0 src/Form/ConfigForm.php \Drupal\jwt\Form\ConfigForm::validateForm()

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/ConfigForm.php, line 151

Class

ConfigForm
Class ConfigForm.

Namespace

Drupal\jwt\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $algorithm = $form_state
    ->getValue('jwt_algorithm');
  $key_id = $form_state
    ->getValue('jwt_key');
  $key = $this->keyRepo
    ->getKey($key_id);
  if ($key != NULL && $key
    ->getKeyType()
    ->getPluginId() != $this->transcoder
    ->getAlgorithmType($algorithm)) {
    $form_state
      ->setErrorByName('jwt_key', $this
      ->t('Incorrect key type selected.'));
  }
  if ($key != NULL && $key
    ->getKeyType()
    ->getConfiguration()['algorithm'] != $algorithm) {
    $form_state
      ->setErrorByName('jwt_key', $this
      ->t('Key does not match algorithm selected.'));
  }
  parent::validateForm($form, $form_state);
}