You are here

function user_registrationpassword_form_user_admin_settings_alter in User registration password 8

Same name and namespace in other branches
  1. 6 user_registrationpassword.module \user_registrationpassword_form_user_admin_settings_alter()
  2. 7 user_registrationpassword.module \user_registrationpassword_form_user_admin_settings_alter()

Implements hook_form_FORM_ID_alter().

File

./user_registrationpassword.module, line 46
Enables password creation on registration form.

Code

function user_registrationpassword_form_user_admin_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
  $config = \Drupal::config('user_registrationpassword.settings');
  $mail_config = \Drupal::config('user_registrationpassword.mail');

  // Render our configuration options.
  $form['registration_cancellation']['user_registrationpassword_registration'] = [
    '#type' => 'radios',
    '#title' => t('Require email verification when a visitor creates an account'),
    '#description' => t('Choose whether new users can set their password directly on the registration form and login during registration (without email confirmation), or if they will be required to validate their email address prior to logging into the site, and will be assigned a system-generated password, or they can set a password during registration, but first have to confirm their account via the activation email sent after registration is complete, before they can log in to the site.'),
    '#options' => [
      UserRegistrationPassword::NO_VERIFICATION => t('Do not require a verification email, and let users set their password on the registration form.'),
      UserRegistrationPassword::VERIFICATION_DEFAULT => t('Require a verification email, but wait for the approval email to let users set their password.'),
      UserRegistrationPassword::VERIFICATION_PASS => t('Require a verification email, but let users set their password directly on the registration form.'),
    ],
    '#default_value' => $config
      ->get('registration'),
  ];

  // Render an option to change first time login link behaviour.
  $form['registration_cancellation']['user_registrationpassword_registration_ftll_expire'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable Account activation link expiration'),
    '#description' => t('This option enables site admins to expire activation links after the expiration time has passed. People are still able to request a new activation email via the password reset form after this time expires to activate their account via a new activation email.'),
    '#default_value' => $config
      ->get('registration_ftll_expire'),
    '#weight' => 7,
  ];

  // Hide this setting by default.
  $form['registration_cancellation']['ftll_timeout'] = [
    '#type' => 'container',
    '#weight' => 8,
    '#states' => [
      'invisible' => [
        'input[name="user_registrationpassword_registration_ftll_expire"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['registration_cancellation']['ftll_timeout']['user_registrationpassword_registration_ftll_timeout'] = [
    '#type' => 'textfield',
    '#title' => t('Account activation link expiration'),
    '#description' => t('Enter the expiration time for the activation link (aka first time login link) sent in the activation email. The default is set to 86400 seconds (= 24 hours).'),
    '#default_value' => $config
      ->get('registration_ftll_timeout'),
    '#maxlength' => 10,
    '#weight' => 8,
  ];

  // Hide the default option.
  $form['registration_cancellation']['user_email_verification']['#access'] = FALSE;

  // Set up available tokens.
  if (\Drupal::moduleHandler()
    ->moduleExists('rpt')) {

    // Hide the option to generate passwords, because we
    // only use the token option the rtp module provides.
    $form['registration_cancellation']['rpt_password_generate']['#access'] = FALSE;

    // We support the Registration Password Tokens module.
    // Add a password to a template with [user:password].
    // See http://drupal.org/project/rpt for more information.
    $email_token_help = t('Available variables are: [site:name], [site:url], [user:display-name], [user:account-name], [user:mail], [user:password], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url], [user:registrationpassword-url].');
  }
  else {
    $email_token_help = t('Available variables are: [site:name], [site:url], [user:display-name], [user:account-name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url], [user:registrationpassword-url].');
  }

  // Render email template settings.
  $form['email_user_registrationpassword'] = [
    '#type' => 'details',
    '#title' => t('Welcome (no approval required, password is set)'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Edit the welcome email messages sent to new members upon registering, when no administrator approval is required and password has already been set.') . ' ' . $email_token_help,
    '#group' => 'email',
  ];
  $form['email_user_registrationpassword']['user_registrationpassword_register_confirmation_with_pass_subject'] = [
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#default_value' => $mail_config
      ->get('register_confirmation_with_pass.subject'),
    '#maxlength' => 180,
  ];
  $form['email_user_registrationpassword']['user_registrationpassword_register_confirmation_with_pass_body'] = [
    '#type' => 'textarea',
    '#title' => t('Body'),
    '#default_value' => $mail_config
      ->get('register_confirmation_with_pass.body'),
    '#rows' => 15,
  ];

  // Reorder the form items back to their original order.
  $form['anonymous_settings']['#weight'] = -2;
  $form['admin_role']['#weight'] = -1;
  $form['registration_cancellation']['#weight'] = 0;
  $form['registration_cancellation']['user_cancel_method']['#weight'] = 3;
  $form['registration_cancellation']['user_registrationpassword_registration']['#weight'] = 2;
  $form['personalization']['#weight'] = 4;
  $form['email_title']['#weight'] = 5;
  $form['email']['#weight'] = 6;
  $form['email_admin_created']['#weight'] = 6;

  // Register our extra submit function.
  $form['#submit'][] = 'user_registrationpassword_admin_settings_submit';
}