You are here

public function ClientForm::validateForm in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/Form/ClientForm.php \Drupal\oauth2_server\Form\ClientForm::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/ClientForm.php, line 237

Class

ClientForm
Class Client Form.

Namespace

Drupal\oauth2_server\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $client_secret = '';
  if (!empty($form_state
    ->getValue('require_client_secret'))) {
    if (!empty($form_state
      ->getValue('client_secret'))) {
      $client_secret = $this->entity
        ->hashClientSecret($form_state
        ->getValue('client_secret'));
      if (!$client_secret) {
        throw new \Exception("Failed to hash client secret");
      }
    }
    elseif (!empty($this->entity->client_secret)) {
      $client_secret = $this->entity->client_secret;
    }
    else {
      $form_state
        ->setErrorByName('client_secret', $this
        ->t('A client secret is required.'));
    }
  }
  $form_state
    ->setValue('client_secret', $client_secret);
}