You are here

public function LdapSsoAdminForm::validateForm in LDAP Single Sign On 8

Same name and namespace in other branches
  1. 8.4 src/Form/LdapSsoAdminForm.php \Drupal\ldap_sso\Form\LdapSsoAdminForm::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/LdapSsoAdminForm.php, line 170

Class

LdapSsoAdminForm
Provides the configuration form SSO under LDAP configuration.

Namespace

Drupal\ldap_sso\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $query_result = $this->storage
    ->getQuery()
    ->condition('status', 1)
    ->execute();
  $enabled_servers = $this->storage
    ->loadMultiple($query_result);

  /* @var \Drupal\ldap_servers\Entity\Server $server */
  foreach ($enabled_servers as $server) {
    if ($server
      ->get('bind_method') == 'user' || $server
      ->get('bind_method') == 'anon_user') {
      $form_state
        ->setErrorByName('ssoEnabled', $this
        ->t("Single sign-on is not valid with the server %sid because that server configuration uses %bind_method. Since the user's credentials are never available to this module with single sign-on enabled, there is no way for the ldap module to bind to the ldap server with credentials.", [
        '%sid' => $server
          ->id(),
        '%bind_method' => $server
          ->getFormattedBind(),
      ]));
    }
  }
  if ($form_state
    ->getValue('redirectOnLogout')) {
    if ($form_state
      ->getValue('logoutRedirectPath') == '') {
      $form_state
        ->setErrorByName('logoutRedirectPath', $this
        ->t('Redirect logout path cannot be blank'));
    }
    try {
      Url::fromUserInput($form_state
        ->getValue('logoutRedirectPath'));
    } catch (\InvalidArgumentException $ex) {
      $form_state
        ->setErrorByName('logoutRedirectPath', $this
        ->t('The path you entered for Redirect logout path is not a valid internal path, internal paths should start with: /, ? or #'));
    }
  }
}