You are here

public function MassPasswordChangeConfirm::buildForm in Mass Password Change 8

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 ConfirmFormBase::buildForm

File

src/Form/MassPasswordChangeConfirm.php, line 85

Class

MassPasswordChangeConfirm
Provides a confirmation form for mass password change action.

Namespace

Drupal\mass_password_change\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Retrieve the accounts to be canceled from the temp store.

  /* @var \Drupal\user\Entity\User[] $accounts */
  $accounts = $this->tempStoreFactory
    ->get('mass_password_change')
    ->get('password_change');
  if (!$accounts) {
    return $this
      ->redirect('entity.user.collection');
  }
  $list = [];
  foreach ($accounts as $account) {
    $uid = $account
      ->id();
    $list[$uid] = $account
      ->getAccountName();
    $form['accounts'][$uid] = [
      '#type' => 'hidden',
      '#value' => $uid,
    ];
  }
  $form['accounts']['#tree'] = TRUE;
  $form['account']['names'] = [
    '#theme' => 'item_list',
    '#items' => $list,
  ];
  $form['password_wrapper'] = [
    '#type' => 'fieldset',
  ];
  $form['password_wrapper']['password'] = [
    '#type' => 'password_confirm',
    '#size' => 25,
    '#description' => $this
      ->t('To change the current user password, enter the new password in both fields.'),
  ];
  $form = parent::buildForm($form, $form_state);
  return $form;
}