You are here

public function SettingsForm::buildForm in Administer Users by Role 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 ConfigFormBase::buildForm

File

src/Form/SettingsForm.php, line 59

Class

SettingsForm
Configure AlbanyWeb settings for this site.

Namespace

Drupal\administerusersbyrole\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('administerusersbyrole.settings');
  $form['roles'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Roles'),
  ];
  $options = [
    AccessManagerInterface::SAFE => $this
      ->t('Allowed'),
    AccessManagerInterface::UNSAFE => $this
      ->t('Forbidden'),
    AccessManagerInterface::PERM => $this
      ->t('Custom'),
  ];
  foreach ($this->accessManager
    ->managedRoles() as $rid => $role) {
    $form['roles'][$rid] = [
      '#type' => 'select',
      '#title' => Html::escape($role
        ->label()),
      '#default_value' => $config
        ->get("roles.{$rid}"),
      '#options' => $options,
      '#required' => TRUE,
    ];
  }
  return parent::buildForm($form, $form_state);
}