public function EnvironmentIndicatorUISettingsForm::validateForm in Environment Indicator 4.x
Same name and namespace in other branches
- 8.3 modules/environment_indicator_ui/src/Form/EnvironmentIndicatorUISettingsForm.php \Drupal\environment_indicator_ui\Form\EnvironmentIndicatorUISettingsForm::validateForm()
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
- modules/
environment_indicator_ui/ src/ Form/ EnvironmentIndicatorUISettingsForm.php, line 59
Class
- EnvironmentIndicatorUISettingsForm
- Configuration form for Environment Indicator.
Namespace
Drupal\environment_indicator_ui\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$colors = [
'fg_color' => $form_state
->getValue('fg_color'),
'bg_color' => $form_state
->getValue('bg_color'),
];
foreach ($colors as $property_name => $color) {
if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) {
$form_state
->setErrorByName($property_name, $this
->t('Please enter a valid hex value.'));
}
}
}