public function SettingsForm::validateForm in uLogin (advanced version) 8
Form validation handler for the ulogin admin settings form.
Overrides FormBase::validateForm
File
- src/
Form/ SettingsForm.php, line 447
Class
- SettingsForm
- Settings form.
Namespace
Drupal\ulogin\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getUserInput();
$providers_main_values = !empty($values['ulogin_providers_main']) ? $values['ulogin_providers_main'] : [];
$providers_enabled_values = $values['ulogin_providers'];
unset($values['ulogin_providers_main']);
unset($values['ulogin_providers']);
$values['ulogin_providers_enabled'] = [];
$values['ulogin_providers_main'] = [];
asort($values['ulogin_providers_weight']);
foreach (array_keys($values['ulogin_providers_weight']) as $provider_id) {
$values['ulogin_providers_enabled'][$provider_id] = $providers_enabled_values[$provider_id];
$values['ulogin_providers_main'][$provider_id] = !empty($providers_main_values[$provider_id]) ? $provider_id : NULL;
}
// Remove weights so they are not saved as variables.
unset($values['ulogin_providers_weight']);
// Process 'required' checkboxes and remove them.
if (empty($values['ulogin_fields_required'])) {
$values['ulogin_fields_required'] = [];
}
else {
foreach ($values['ulogin_fields_required'] as $key => $value) {
if (!empty($value)) {
$values['ulogin_fields_required'][$key] = $key;
}
}
}
$values['ulogin_fields_optional'] = array_diff_assoc($values['ulogin_fields'], $values['ulogin_fields_required']);
unset($values['ulogin_fields']);
$form_state
->setValues($values);
parent::validateForm($form, $form_state);
}