public function LtiToolProviderAttributesSettingsForm::buildForm in LTI Tool Provider 2.x
Same name and namespace in other branches
- 8 modules/lti_tool_provider_attributes/src/Form/LtiToolProviderAttributesSettingsForm.php \Drupal\lti_tool_provider_attributes\Form\LtiToolProviderAttributesSettingsForm::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_attributes/ src/ Form/ LtiToolProviderAttributesSettingsForm.php, line 21
Class
Namespace
Drupal\lti_tool_provider_attributes\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $filter = '') : array {
$settings = $this
->config('lti_tool_provider_attributes.settings');
$mapped_attributes = $settings
->get('mapped_attributes');
$lti_launch = $this
->config('lti_tool_provider.settings')
->get('lti_launch');
$form['mapped_attributes'] = [
'#type' => 'table',
'#tree' => TRUE,
'#caption' => t('This page allows you to map LTI attrubutes to Drupal user attributes. This is applied every time a user logs in via LTI.'),
'#header' => [
t('User Field'),
t('LTI Attribute'),
],
];
/* @var $entityManager Drupal\Core\Entity\EntityFieldManagerInterface */
$entityManager = Drupal::service('entity_field.manager');
$userFieldDefinitions = $entityManager
->getFieldDefinitions('user', 'user');
foreach ($userFieldDefinitions as $key => $field) {
$type = $field
->getType();
if ($type === 'string') {
$form['mapped_attributes'][$key] = [
'user_attribute' => [
'#type' => 'item',
'#title' => $field
->getLabel(),
],
'lti_attribute' => [
'#type' => 'select',
'#required' => FALSE,
'#empty_option' => t('None'),
'#empty_value' => TRUE,
'#default_value' => $mapped_attributes[$key],
'#options' => array_combine($lti_launch, $lti_launch),
],
];
}
}
return parent::buildForm($form, $form_state);
}