public function CasAttributesSettings::submitForm in CAS Attributes 2.x
Same name and namespace in other branches
- 8 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 293
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',
]));
// Split each line into an entry in an array.
$submittedList = preg_split('/\\r\\n|\\r|\\n/', $form_state
->getValue([
'general',
'token_allowed_attributes',
]));
// Trim and convert to lower case each line.
$submittedList = array_map(function ($line) {
return strtolower(trim($line));
}, $submittedList);
// Remove empty lines.
$submittedList = array_filter($submittedList);
$config
->set('token_allowed_attributes', $submittedList);
$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);
}