color_palette_color_value

color_palette_color_value($element, $input = FALSE, FormStateInterface $form_state)

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.

File

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

Code

function color_palette_color_value($element, $input = FALSE, 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'];
    }
  }
}
doc_Drupal
2016-10-29 08:50:08
Comments
Leave a Comment

Please login to continue.