You are here

public function PasswordPolicyRolesForm::buildForm in Password Policy 8.3

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/PasswordPolicyRolesForm.php, line 52

Class

PasswordPolicyRolesForm
The form to select roles that are associated to the policy.

Namespace

Drupal\password_policy\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /** @var \Drupal\password_policy\Entity\PasswordPolicy $policy */
  $policy = $cached_values['password_policy'];
  $options = [];
  foreach ($this->storage
    ->loadMultiple() as $role) {
    $options[$role
      ->id()] = $role
      ->label();
  }
  unset($options[AccountInterface::ANONYMOUS_ROLE]);
  $form['roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Apply to Roles'),
    '#description' => $this
      ->t('Select Roles to which this policy applies.'),
    '#options' => $options,
    '#default_value' => $policy
      ->getRoles(),
  ];
  return $form;
}