You are here

function keycloak_form_openid_connect_admin_settings_validate in Keycloak OpenID Connect 8

Custom validation handler to check submitted values of the settings form.

Parameters

array $form: An associative array containing the structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 string reference to 'keycloak_form_openid_connect_admin_settings_validate'
keycloak_form_openid_connect_admin_settings_alter in ./keycloak.module
Implements hook_form_FORM_ID_alter() for openid_connect_admin_settings.

File

./keycloak.module, line 81
Hook implementations of the Keycloak module.

Code

function keycloak_form_openid_connect_admin_settings_validate(array &$form, FormStateInterface $form_state) {

  // Whether Keycloak is enabled.
  if (empty($form_state
    ->getValue([
    'clients_enabled',
    'keycloak',
  ]))) {

    // Don't bother with validating, as Keycloak won't be used.
    return;
  }

  // Get Keycloak setting values.
  $settings = $form_state
    ->getValue([
    'clients',
    'keycloak',
    'settings',
  ]);

  // Whether a client ID is given.
  if (empty($settings['client_id'])) {
    $form_state
      ->setErrorByName('clients][keycloak][settings][client_id', 'The Keycloak client ID is missing.');
  }

  // Whether a client secret is given.
  if (empty($settings['client_secret'])) {
    $form_state
      ->setErrorByName('clients][keycloak][settings][client_secret', 'The Keycloak client secret is missing.');
  }

  // Whether a Keycloak base URL is given.
  if (empty($settings['keycloak_base'])) {
    $form_state
      ->setErrorByName('clients][keycloak][settings][keycloak_base', 'The Keycloak base URL is missing.');
  }

  // Whether a Keycloak realm is given.
  if (empty($settings['keycloak_realm'])) {
    $form_state
      ->setErrorByName('clients][keycloak][settings][keycloak_realm', 'The Keycloak realm is missing.');
  }
}