You are here

public function ShortcutPerRoleSettingsForm::buildForm in Shortcut per Role 8

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/ShortcutPerRoleSettingsForm.php, line 31

Class

ShortcutPerRoleSettingsForm
Configure Shortcut per Role settings for this site.

Namespace

Drupal\shortcutperrole\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('shortcutperrole.settings');
  $roles = user_roles();
  $sets = ShortcutSet::loadMultiple();
  $options = array();
  foreach ($sets as $name => $set) {
    $options[$name] = $set
      ->label();
  }
  $form['#title'] = $this
    ->t('Assign Shortcuts for Role');
  foreach ($roles as $rid => $role) {
    $default_value_ss = $config
      ->get('role.' . $rid);
    $form['shortcutperrole'][$rid] = array(
      '#type' => 'select',
      '#default_value' => isset($default_value_ss) ? $default_value_ss : 'default',
      '#options' => $options,
      '#title' => $role
        ->label(),
    );
  }
  return parent::buildForm($form, $form_state);
}