You are here

public function OpenIDConnectClientBase::validateConfigurationForm in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x src/Plugin/OpenIDConnectClientBase.php \Drupal\openid_connect\Plugin\OpenIDConnectClientBase::validateConfigurationForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormInterface::validateConfigurationForm

File

src/Plugin/OpenIDConnectClientBase.php, line 226

Class

OpenIDConnectClientBase
Base class for OpenID Connect client plugins.

Namespace

Drupal\openid_connect\Plugin

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {

  // Provider label as array for StringTranslationTrait::t() argument.
  $provider = [
    '@provider' => $this
      ->getPluginDefinition()['label'],
  ];

  // Get plugin setting values.
  $configuration = $form_state
    ->getValues();

  // Whether a client ID is given.
  if (empty($configuration['client_id'])) {
    $form_state
      ->setErrorByName('client_id', $this
      ->t('The client ID is missing for @provider.', $provider));
  }

  // Whether a client secret is given.
  if (empty($configuration['client_secret'])) {
    $form_state
      ->setErrorByName('client_secret', $this
      ->t('The client secret is missing for @provider.', $provider));
  }
}