function color_palette_color_value
Same name in other branches
- 7.x modules/color/color.module \color_palette_color_value()
- 9 core/modules/color/color.module \color_palette_color_value()
Determines the value for a palette color field.
Parameters
array $element: The form element whose value is being populated.
string|bool $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
string The data that will appear in the $form_state->getValues() collection for this element. Return nothing to use the default.
1 string reference to 'color_palette_color_value'
- color_scheme_form in core/
modules/ color/ color.module - Form constructor for the color configuration form for a particular theme.
File
-
core/
modules/ color/ color.module, line 321
Code
function color_palette_color_value($element, $input, FormStateInterface $form_state) {
// If we suspect a possible cross-site request forgery attack, only accept
// hexadecimal CSS color strings from user input, to avoid problems when this
// value is used in the JavaScript preview.
if ($input !== FALSE) {
// Start with the provided value for this textfield, and validate that if
// necessary, falling back on the default value.
$value = Textfield::valueCallback($element, $input, $form_state);
$complete_form = $form_state->getCompleteForm();
if (!$value || !isset($complete_form['#token']) || color_valid_hexadecimal_string($value) || \Drupal::csrfToken()->validate($form_state->getValue('form_token'), $complete_form['#token'])) {
return $value;
}
else {
return $element['#default_value'];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.