function _ldap_authentication_login_form_alter in Lightweight Directory Access Protocol (LDAP) 8.3
Same name and namespace in other branches
- 8.4 ldap_authentication/ldap_authentication.module \_ldap_authentication_login_form_alter()
- 8.2 ldap_authentication/ldap_authentication.inc \_ldap_authentication_login_form_alter()
- 7.2 ldap_authentication/ldap_authentication.inc \_ldap_authentication_login_form_alter()
- 7 ldap_authentication/ldap_authentication.inc \_ldap_authentication_login_form_alter()
Helper function for the user login block.
Relevant in ldap_authn_form_user_login_block_alter and ldap_authn_form_user_login_alter.
Parameters
array $form: The form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
string $form_id: The form ID.
2 calls to _ldap_authentication_login_form_alter()
- ldap_authentication_form_user_login_block_alter in ldap_authentication/
ldap_authentication.module - Implements hook_form_FORM_ID_alter().
- ldap_authentication_form_user_login_form_alter in ldap_authentication/
ldap_authentication.module - Implements hook_form_FORM_ID_alter().
File
- ldap_authentication/
ldap_authentication.module, line 211 - This module injects itself into Drupal's Authentication stack.
Code
function _ldap_authentication_login_form_alter(array &$form, FormStateInterface &$form_state, $form_id) {
if (!LdapAuthenticationConfiguration::hasEnabledAuthenticationServers()) {
return;
}
$config = \Drupal::config('ldap_authentication.settings');
// Add validate function to test for LDAP authentication
// should be placed after user_login_authenticate_validate
// 1. user_login_name_validate
// 2. user_login_authenticate_validate
// 3. external authentication validate functions
// 4. user_login_final_validate
//
// As articulated above user_login_default_validators() in user.module without
// any other external authentication modules, this array will start out as: [
// 'user_login_name_validate',
// 'user_login_authenticate_validate',
// 'user_login_final_validate'
// ].
if (@in_array('::validateAuthentication', $form['#validate']) && $config
->get('authenticationMode')) {
$key = array_search('::validateAuthentication', $form['#validate']);
$form['#validate'][$key] = 'ldap_authentication_core_override_user_login_authenticate_validate';
array_splice($form['#validate'], $key + 1, 0, 'ldap_authentication_user_login_authenticate_validate');
}
// Add help information for entering in username/password.
if ($config
->get('loginUIUsernameTxt')) {
$form['name']['#description'] = $config
->get('loginUIUsernameTxt');
}
if ($config
->get('loginUIPasswordTxt')) {
$form['pass']['#description'] = $config
->get('loginUIPasswordTxt');
}
if ($config
->get('emailTemplateUsageRedirectOnLogin')) {
$form['#submit'][] = 'Drupal\\ldap_authentication\\Routing\\EmailTemplateService::checkForEmailTemplate';
}
}