You are here

public function ConfirmationForm::buildForm in Auto Purge Users 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/ConfirmationForm.php \Drupal\purge_users\Form\ConfirmationForm::buildForm()
  2. 8 src/Form/ConfirmationForm.php \Drupal\purge_users\Form\ConfirmationForm::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 ConfirmFormBase::buildForm

File

src/Form/ConfirmationForm.php, line 66

Class

ConfirmationForm
Class ConfirmationForm.

Namespace

Drupal\purge_users\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $accounts = NULL) {
  $form = parent::buildForm($form, $form_state);
  $uids = purge_users_get_user_ids();
  $form['accounts'] = [
    '#prefix' => '<ul>',
    '#suffix' => '</ul>',
    '#tree' => TRUE,
  ];
  $uidsToShow = array_slice($uids, 0, self::NUMBER_OF_USERS_TO_SHOW);
  $accounts = User::loadMultiple($uidsToShow);
  foreach ($accounts as $account) {

    // Prevent user 1 from being canceled.
    if ($account
      ->get('uid')->value <= 1) {
      continue;
    }
    $form['accounts']['uid' . $account
      ->get('uid')->value] = [
      '#type' => 'markup',
      '#value' => $account
        ->get('uid')->value,
      '#prefix' => '<li>',
      '#suffix' => $account
        ->get('name')->value . " &lt;" . $account
        ->get('mail')->value . "&gt; </li>\n",
    ];
  }
  if (count($uids) > self::NUMBER_OF_USERS_TO_SHOW) {
    $form['accounts']['and_more'] = [
      '#type' => 'markup',
      '#markup' => $this
        ->t('...and @more more.', [
        '@more' => count($uids) - self::NUMBER_OF_USERS_TO_SHOW,
      ]),
      '#prefix' => '<li>',
      '#suffix' => '</li>',
    ];
  }
  return parent::buildForm($form, $form_state);
}