You are here

public function MassPasswordResetForm::buildForm in Mass Password Reset 8

Same name and namespace in other branches
  1. 2.x src/Form/MassPasswordResetForm.php \Drupal\mass_pwreset\Form\MassPasswordResetForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MassPasswordResetForm.php, line 23

Class

MassPasswordResetForm
Mass Password Reset Form.

Namespace

Drupal\mass_pwreset\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['options'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Role Options'),
    '#description' => $this
      ->t('Select all users or specific roles below.'),
    '#open' => TRUE,
  ];
  $form['options']['authenticated'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Authenticated Role'),
    '#description' => $this
      ->t('Selecting Authenticated will reset all users.'),
    '#open' => TRUE,
  ];
  $form['options']['authenticated']['authenticated_role'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Select all users'),
    '#required' => FALSE,
  ];
  $form['options']['custom_roles'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Roles'),
    '#open' => TRUE,
  ];
  $form['options']['custom_roles']['selected_roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Select Roles to Reset'),
    '#options' => mass_pwreset_get_custom_roles(),
    '#required' => FALSE,
    '#states' => [
      'disabled' => [
        ':input[name="authenticated_role"]' => array(
          'checked' => TRUE,
        ),
      ],
    ],
  ];
  $form['notify'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Notify Users'),
    '#open' => TRUE,
  ];
  $form['notify']['notify_active_users'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Notify active users of password reset via email'),
    '#default_value' => 0,
  ];
  $form['notify']['notify_blocked_users'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Notify blocked users of password reset via email'),
    '#default_value' => 0,
    '#states' => [
      'visible' => [
        ':input[name="notify_active_users"]' => array(
          'checked' => TRUE,
        ),
      ],
    ],
  ];
  $form['admin'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Administrator Reset'),
    '#description' => $this
      ->t('Include the administrative superuser id 1 account in the list of passwords being reset.'),
    '#open' => FALSE,
  ];
  $form['admin']['include_admin_user'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include admin user (uid1)'),
    '#default_value' => 0,
  ];

  // Resetting your own password causes an error at the end of the batch.
  $form['current_user_note'] = [
    '#type' => 'item',
    '#markup' => $this
      ->t('The user submitting this form will not be included in the password reset batch.'),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['reset_passwords'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Reset Passwords'),
  ];
  return $form;
}