You are here

function simple_ldap_user_form_user_login_form_alter in Simple LDAP 8

Implements hook_form_FORM_ID_alter().

File

modules/simple_ldap_user/simple_ldap_user.module, line 10

Code

function simple_ldap_user_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  // Put our validation function after Drupal's auth (::validateAuthentication)
  // and before ::validateFinal. This way, we have the chance to set the uid
  // so ::validateFinal passes. By doing it this way, we still benefit from
  // Drupal's flood control.
  foreach ($form['#validate'] as $key => $validation) {
    if ($validation === '::validateAuthentication') {
      $first_array = array_slice($form['#validate'], 0, $key + 1);
      $first_array[] = 'simple_ldap_user_login_validate';
      array_splice($form['#validate'], 0, $key + 1, $first_array);
      break;
    }
  }
}