You are here

public function CookiebotForm::validateForm in Cookiebot - Cookie consent, Cookie monitoring and Cookie control 8

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

src/Form/CookiebotForm.php, line 242

Class

CookiebotForm
Cookiebot settings form.

Namespace

Drupal\cookiebot\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $cbid_trimmed = trim($form_state
    ->getValue('cookiebot_cbid'));
  $form_state
    ->setValue('cookiebot_cbid', $cbid_trimmed);
  if (!empty($cbid_trimmed) && !preg_match('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/', $cbid_trimmed)) {
    $form_state
      ->setErrorByName('cookiebot_cbid', $this
      ->t('The entered Domain Group ID is not formatted correctly.'));
  }
}