function UserDevelGenerate::settingsForm

Same name in other branches
  1. 8.x-1.x devel_generate/src/Plugin/DevelGenerate/UserDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\UserDevelGenerate::settingsForm()
  2. 5.x devel_generate/src/Plugin/DevelGenerate/UserDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\UserDevelGenerate::settingsForm()

Overrides DevelGenerateBase::settingsForm

File

devel_generate/src/Plugin/DevelGenerate/UserDevelGenerate.php, line 93

Class

UserDevelGenerate
Provides a UserDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
    $form['num'] = [
        '#type' => 'number',
        '#title' => $this->t('How many users would you like to generate?'),
        '#default_value' => $this->getSetting('num'),
        '#required' => TRUE,
        '#min' => 0,
    ];
    $form['kill'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Delete all users (except user id 1) before generating new users.'),
        '#default_value' => $this->getSetting('kill'),
    ];
    $options = user_role_names(TRUE);
    unset($options[AccountInterface::AUTHENTICATED_ROLE]);
    $form['roles'] = [
        '#type' => 'checkboxes',
        '#title' => $this->t('Which roles should the users receive?'),
        '#description' => $this->t('Users always receive the <em>authenticated user</em> role.'),
        '#options' => $options,
    ];
    $form['pass'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Password to be set'),
        '#default_value' => $this->getSetting('pass'),
        '#size' => 32,
        '#description' => $this->t('Leave this field empty if you do not need to set a password'),
    ];
    $options = [
        1 => $this->t('Now'),
    ];
    foreach ([
        3600,
        86400,
        604800,
        2592000,
        31536000,
    ] as $interval) {
        $options[$interval] = $this->dateFormatter
            ->formatInterval($interval, 1) . ' ' . $this->t('ago');
    }
    $form['time_range'] = [
        '#type' => 'select',
        '#title' => $this->t('How old should user accounts be?'),
        '#description' => $this->t('User ages will be distributed randomly from the current time, back to the selected time.'),
        '#options' => $options,
        '#default_value' => 604800,
    ];
    return $form;
}