You are here

public function LtiToolProviderRolesSettingsForm::buildForm in LTI Tool Provider 8

Same name and namespace in other branches
  1. 2.x modules/lti_tool_provider_roles/src/Form/LtiToolProviderRolesSettingsForm.php \Drupal\lti_tool_provider_roles\Form\LtiToolProviderRolesSettingsForm::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 ConfigFormBase::buildForm

File

modules/lti_tool_provider_roles/src/Form/LtiToolProviderRolesSettingsForm.php, line 29

Class

LtiToolProviderRolesSettingsForm

Namespace

Drupal\lti_tool_provider_roles\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $filter = '') : array {
  $settings = $this
    ->config('lti_tool_provider_roles.settings');
  $mapped_roles = $settings
    ->get('mapped_roles');
  $lti_roles = $this
    ->config('lti_tool_provider.settings')
    ->get('lti_roles');
  $form['mapped_roles'] = [
    '#type' => 'table',
    '#tree' => true,
    '#caption' => t('This page allows you to map LTI roles to Drupal user roles. This is applied every time a user logs in via LTI. Please note that if roles are mapped and they are not present on the LMS, they will be removed from the Drupal user. Please be careful when setting this for the authenticated user role.'),
    '#header' => [
      t('User Role'),
      t('LTI Role'),
    ],
  ];
  foreach (user_roles(true) as $key => $user_role) {
    $form['mapped_roles'][$key] = [
      'user_role' => [
        '#type' => 'item',
        '#title' => $user_role
          ->label(),
      ],
      'lti_role' => [
        '#type' => 'select',
        '#required' => false,
        '#empty_option' => t('None'),
        '#empty_value' => true,
        '#default_value' => $mapped_roles[$key],
        '#options' => array_combine($lti_roles, $lti_roles),
      ],
    ];
  }
  return parent::buildForm($form, $form_state);
}