public function SkinsEditForm::validateForm in Skinr 8.2
Form validation 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 FormBase::validateForm
File
- skinr_ui/
src/ Form/ SkinsEditForm.php, line 296 - Contains Drupal\skinr_ui\Form\SkinsEditForm.
Class
Namespace
Drupal\skinr_ui\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$element_type = $form_state
->getValue('element_type');
$element = $form_state
->getValue('element');
$error = FALSE;
if ($form_state
->hasValue('skinr_settings')) {
foreach ($form_state
->getValue('skinr_settings') as $section_theme_name => $section_theme) {
if (isset($section_theme['groups']['_additional']['_additional'])) {
// Validate additional classes field.
if (preg_match('/[^a-zA-Z0-9\\-\\_\\s]/', $section_theme['groups']['_additional']['_additional'])) {
$form_state
->setErrorByName('skinr_settings][' . $section_theme_name . '][groups][_additional][_additional', t('Additional classes for Skinr may only contain alphanumeric characters, spaces, - and _.'));
$error = TRUE;
}
}
}
}
if (!$error) {
$groups = skinr_get_group_info();
// Add hard-coded additional classes group.
$groups['_additional'] = array(
'title' => t('Additional'),
'description' => t('Additional custom classes.'),
'weight' => 0,
);
if ($form_state
->hasValue('skinr_settings')) {
$skinr_settings = $form_state
->getValue('skinr_settings');
foreach ($skinr_settings as $section_theme_name => $section_theme) {
// Unset active tab variables.
foreach ($section_theme['groups'] as $skin_name => $options) {
if (strpos($skin_name, '__groups__active_tab') !== FALSE) {
unset($skinr_settings[$section_theme_name]['groups'][$skin_name]);
continue;
}
}
// Undo any grouping to ease processing on submit.
foreach ($groups as $group_name => $group) {
if (!empty($section_theme['groups'][$group_name]) && is_array($section_theme['groups'][$group_name])) {
$group_values = $section_theme['groups'][$group_name];
unset($skinr_settings[$section_theme_name]['groups'][$group_name]);
$skinr_settings[$section_theme_name] = array_merge($skinr_settings[$section_theme_name], $group_values);
}
}
unset($skinr_settings[$section_theme_name]['groups']);
}
$form_state
->setValue('skinr_settings', $skinr_settings);
}
}
}