Commit 7a1b8791 authored by George's avatar George
Browse files

Issue #3285369 - Add configuration option to toggle betweem accountName & displayName.

parent e25041e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ field_based_login:
  field: ''
  allow_user_name: 1
  allow_user_email: 0
  user_email_source: 'display_name'
  label: ''
  field_desc: ''
langcode: en
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@ fbl.settings:
        allow_user_email:
          type: boolean
          label: 'Allow login with e-mail'
        user_email_source:
          type: string
          label: 'Source for email/username'
        label:
          type: text
          label: 'User name field label'
+2 −2
Original line number Diff line number Diff line
fbl.configuration:
  base_route: fbl.configuration
  title: 'Settings'
  base_route: entity.user.collection
  title: 'Field based login'
  route_name: fbl.configuration
+10 −1
Original line number Diff line number Diff line
@@ -145,10 +145,19 @@ function fbl_login_name_validate($form, FormStateInterface &$form_state) {
    }

    // Load user object by its email.
    /** @var \Drupal\user\Entity\User $user_load_by_mail */
    $user_load_by_mail = user_load_by_mail($login_input);
    if ($user_load_by_mail && $allow_user_login_by_email) {
      $user_not_found = FALSE;
      $form_state->setValue('name', $user_load_by_mail->getDisplayName());
      // Use display name by default.
      $name = $user_load_by_mail->getDisplayName();
      // Check to see if account name is specified.
      // If so, use account name instead.
      if ($fbl_value['user_email_source'] == 'account_name') {
        $name = $user_load_by_mail->getAccountName();
      }
      // Set name.
      $form_state->setValue('name', $name);
    }

    // User not found.
+20 −2
Original line number Diff line number Diff line
@@ -103,9 +103,9 @@ class FblConfiguration extends ConfigFormBase {
      '#type' => 'select',
      '#title' => $this->t('Unique field'),
      '#options' => $bundleFields,
      '#empty_option' => '- Select -',
      '#empty_option' => $this->t('- Select -'),
      '#default_value' => $default_value['field'] ?? '',
      '#description' => $this->t('Unique field to allow users to login with this field. Note : Selected field will become unique filed.'),
      '#description' => $this->t('Unique field to allow users to login with this field. Note: Selected field will become unique.'),
    ];

    $form['field_based_login']['allow_user_name'] = [
@@ -120,6 +120,24 @@ class FblConfiguration extends ConfigFormBase {
      '#default_value' => $default_value['allow_user_email'] ?? '',
    ];

    $sources = [
      'account_name' => $this->t('Account name'),
      'display_name' => $this->t('Display name'),
    ];
    $form['field_based_login']['user_email_source'] = [
      '#type' => 'select',
      '#title' => $this->t('Source for email/username'),
      '#options' => $sources,
      '#empty_option' => $this->t('- Select -'),
      '#description' => $this->t('Select where user email/name should be pulled from.'),
      '#default_value' => $default_value['user_email_source'] ?? 'display_name',
      '#states' => [
        'visible' => [
          ':input[name="field_based_login[allow_user_email]"]' => ['checked' => TRUE],
        ],
      ],
    ];

    $form['field_based_login']['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('User login form - User name field Label'),