public function CasAttributesSettings::submitForm in CAS Attributes 8
Same name and namespace in other branches
- 2.x src/Form/CasAttributesSettings.php \Drupal\cas_attributes\Form\CasAttributesSettings::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ CasAttributesSettings.php, line 281
Class
- CasAttributesSettings
- CAS Attributes settings form.
Namespace
Drupal\cas_attributes\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('cas_attributes.settings');
$config
->set('sitewide_token_support', $form_state
->getValue([
'general',
'sitewide_token_support',
]));
$field_data = $form_state
->getValue('field');
$field_mappings = array_filter(array_map('trim', $field_data['mappings']));
$config
->set('field.sync_frequency', $field_data['sync_frequency'])
->set('field.overwrite', $field_data['overwrite']);
$config
->set('field.mappings', $field_mappings);
$role_data = $form_state
->getValue('role');
$role_map = [];
// Filter out invalid mappings before saving.
foreach ($role_data['mappings'] as $mapping) {
// Ignore any mappings that have the delete flag.
if (isset($mapping['delete']) && $mapping['delete']) {
continue;
}
// Ignore any mappings that have incomplete data.
if (empty($mapping['attribute']) || empty($mapping['value'])) {
continue;
}
// Don't save a value for the delete checkbox. It's not important.
unset($mapping['delete']);
$role_map[] = $mapping;
}
$config
->set('role.sync_frequency', $role_data['sync_frequency'])
->set('role.deny_login_no_match', $role_data['deny_login_no_match'])
->set('role.deny_registration_no_match', $role_data['deny_registration_no_match'])
->set('role.mappings', $role_map);
$config
->save();
parent::submitForm($form, $form_state);
}