You are here

public function BulkAddCasUsers::buildForm in CAS 8

Same name and namespace in other branches
  1. 2.x src/Form/BulkAddCasUsers.php \Drupal\cas\Form\BulkAddCasUsers::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/BulkAddCasUsers.php, line 31

Class

BulkAddCasUsers
Class BulkAddCasUsers.

Namespace

Drupal\cas\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['intro'] = [
    '#prefix' => '<p>',
    '#markup' => $this
      ->t('Use this form to pre-register one or more users, allowing them to log in using CAS.'),
    '#suffix' => '</p>',
  ];
  $form['cas_usernames'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('CAS username(s)'),
    '#required' => TRUE,
    '#default_value' => '',
    '#description' => $this
      ->t('Enter one username per line.'),
  ];
  $form['email_hostname'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Email address'),
    '#description' => $this
      ->t("The email domain name used to combine with the username to form the user's email address. If your user's email address is usually provided via a CAS attribute, that will not work here because CAS attributes are not available."),
    '#field_prefix' => $this
      ->t('username@'),
    '#required' => TRUE,
    '#default_value' => $this
      ->config('cas.settings')
      ->get('user_accounts.email_hostname'),
  ];
  $roles = array_map([
    '\\Drupal\\Component\\Utility\\Html',
    'escape',
  ], user_role_names(TRUE));
  $form['roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Role(s)'),
    '#options' => $roles,
    '#description' => $this
      ->t('Optionally assign one or more roles to each user. Note that if you have CAS configured to assign roles during automatic registration on login, those will be ignored.'),
  ];
  $form['roles'][RoleInterface::AUTHENTICATED_ID] = [
    '#default_value' => TRUE,
    '#disabled' => TRUE,
  ];
  $form['extra_info'] = [
    '#prefix' => '<p>',
    '#markup' => $this
      ->t("Note that because CAS attributes are only available when a user authenticates with CAS, any role or field assignment based on attributes will not be available."),
    '#suffix' => '</p>',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Create new accounts'),
  ];
  return $form;
}