You are here

function logintoboggan_form_alter in LoginToboggan 8

Same name and namespace in other branches
  1. 5 logintoboggan.module \logintoboggan_form_alter()
  2. 6 logintoboggan.module \logintoboggan_form_alter()
  3. 7 logintoboggan.module \logintoboggan_form_alter()

Implements hook_form_alter().

File

./logintoboggan.module, line 147
LoginToboggan module.

Code

function logintoboggan_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login_form':
      if (\Drupal::config('logintoboggan.settings')
        ->get('login_with_email')) {

        // Ensure a valid validate array.
        $form['#validate'] = is_array($form['#validate']) ? $form['#validate'] : [];

        // LT's validation function must run first.
        array_unshift($form['#validate'], 'logintoboggan_user_login_validate');

        // Use theme functions to print the username field's textual labels.
        $lt_username_title = [
          '#theme' => 'lt_username_title',
          '#form_id' => $form_id,
        ];
        $form['name']['#title'] = \Drupal::service('renderer')
          ->render($lt_username_title);
        $lt_username_description = [
          '#theme' => 'lt_username_description',
          '#form_id' => $form_id,
        ];
        $form['name']['#description'] = \Drupal::service('renderer')
          ->render($lt_username_description);

        // Use theme functions to print the password field's textual labels.
        $lt_password_title = [
          '#theme' => 'lt_password_title',
          '#form_id' => $form_id,
        ];
        $form['pass']['#title'] = \Drupal::service('renderer')
          ->render($lt_password_title);
        $lt_password_description = [
          '#theme' => 'lt_password_description',
          '#form_id' => $form_id,
        ];
        $form['pass']['#description'] = \Drupal::service('renderer')
          ->render($lt_password_description);
      }
      break;
    case 'user_admin_settings':

      // Disable the checkbox at the Account settings page which controls
      // whether e-mail verification is required upon registration or not.
      // The LoginToboggan module implements e-mail verification functionality
      // differently than core, and will control whether e-mail verification is
      // required or not.
      if (\Drupal::config('logintoboggan.settings')
        ->get('user_email_verification') == '1') {
        $form['registration_cancellation']['user_email_verification']['#disabled'] = TRUE;
        $form['registration_cancellation']['user_email_verification']['#description'] = t('This setting has been
      locked by Logintoboggan.
      You can change this setting by modifying the <strong>Set password</strong> checkbox at <a href=":link">LoginToboggan settings page</a>.', [
          ':link' => Url::fromRoute('logintobogganform.settings')
            ->toString(),
        ]);
      }
      break;
  }
}