You are here

function eu_cookie_compliance_validate_hex in EU Cookie Compliance (GDPR Compliance) 8

Same name and namespace in other branches
  1. 7.2 eu_cookie_compliance.admin.inc \eu_cookie_compliance_validate_hex()
  2. 7 eu_cookie_compliance.admin.inc \eu_cookie_compliance_validate_hex()

Validate field for a HEX value if a value is set.

Parameters

array $element: Element.

\Drupal\Core\Form\FormStateInterface $form_state: Form State Interface.

1 string reference to 'eu_cookie_compliance_validate_hex'
EuCookieComplianceConfigForm::buildForm in src/Form/EuCookieComplianceConfigForm.php
Form constructor.

File

./eu_cookie_compliance.module, line 685
The main file for the EU Cookie Compliance module.

Code

function eu_cookie_compliance_validate_hex(array $element, FormStateInterface $form_state) {

  // Handle version 2 of jquery colorpicker.
  if (_eu_cookie_compliance_get_jquery_colorpicker_version() === 2) {
    $element['#value'] = substr($element['#value'], 1);
  }
  if (!empty($element['#value']) && !preg_match('/^[0-9a-fA-F]{3,6}$/', $element['#value'])) {
    $form_state
      ->setError($element, t('%name must be a HEX value (without leading #) or empty.', [
      '%name' => $element['#title'],
    ]));
  }
}