You are here

function color_scheme_form_validate in Drupal 8

Same name and namespace in other branches
  1. 6 modules/color/color.module \color_scheme_form_validate()
  2. 7 modules/color/color.module \color_scheme_form_validate()
  3. 9 core/modules/color/color.module \color_scheme_form_validate()

Form validation handler for color_scheme_form().

See also

color_scheme_form_submit()

1 string reference to 'color_scheme_form_validate'
color_form_system_theme_settings_alter in core/modules/color/color.module
Implements hook_form_FORM_ID_alter().

File

core/modules/color/color.module, line 358
Allows users to change the color scheme of themes.

Code

function color_scheme_form_validate($form, FormStateInterface $form_state) {

  // Only accept hexadecimal CSS color strings to avoid XSS upon use.
  foreach ($form_state
    ->getValue('palette') as $key => $color) {
    if (!color_valid_hexadecimal_string($color)) {
      $form_state
        ->setErrorByName('palette][' . $key, t('You must enter a valid hexadecimal color value for %name.', [
        '%name' => $form['color']['palette'][$key]['#title'],
      ]));
    }
  }
}