function email_registration_form_user_login_form_alter in Email Registration 8
Implements hook_form_FORM_ID_alter().
File
- ./
email_registration.module, line 159 - Allows users to register with an email address as their username.
Code
function email_registration_form_user_login_form_alter(&$form, FormStateInterface $form_state) {
$config = \Drupal::config('email_registration.settings');
$login_with_username = $config
->get('login_with_username');
$form['name']['#title'] = $login_with_username ? t('Email or username') : t('Email');
$form['name']['#description'] = $login_with_username ? t('Enter your email address or username.') : t('Enter your email address.');
$form['name']['#element_validate'][] = 'email_registration_user_login_validate';
$form['pass']['#description'] = t('Enter the password that accompanies your email address.');
// Allow client side validation of input format.
$form['name']['#type'] = $login_with_username ? 'textfield' : 'email';
$form['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
// Make sure the login form cache is invalidated when the setting changes.
$form['#cache']['tags'][] = 'config:email_registration.settings';
}