You are here

public function EuCookieComplianceConfigForm::validateForm in EU Cookie Compliance (GDPR Compliance) 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EuCookieComplianceConfigForm.php \Drupal\eu_cookie_compliance\Form\EuCookieComplianceConfigForm::validateForm()

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/EuCookieComplianceConfigForm.php, line 1031

Class

EuCookieComplianceConfigForm
Provides settings for eu_cookie_compliance module.

Namespace

Drupal\eu_cookie_compliance\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  if ($form_state
    ->getValue('popup_agreed_enabled')) {
    if (empty($form_state
      ->getValue('popup_agreed'))) {
      $form_state
        ->setErrorByName('popup_agreed', $this
        ->t('@name field is required', [
        '@name' => '"Thank you" banner message',
      ]));
    }
    if (empty($form_state
      ->getValue('popup_find_more_button_message'))) {
      $form_state
        ->setErrorByName('popup_find_more_button_message', $this
        ->t('@name field is required', [
        '@name' => 'More info button label',
      ]));
    }
    if (empty($form_state
      ->getValue('popup_hide_button_message'))) {
      $form_state
        ->setErrorByName('popup_hide_button_message', $this
        ->t('@name field is required', [
        '@name' => 'Hide button label',
      ]));
    }
  }

  // Set popup_info_template value to 'new' if method is not 'consent by
  // default'.
  if ($form_state
    ->getValue('method') !== 'default') {
    $form_state
      ->setValue('popup_info_template', 'new');
  }

  // Validate cookie name against valid characters.
  if (preg_match('/[&\'\\x00-\\x20\\x22\\x28-\\x29\\x2c\\x2f\\x3a-\\x40\\x5b-\\x5d\\x7b\\x7d\\x7f]/', $form_state
    ->getValue('cookie_name'))) {
    $form_state
      ->setErrorByName('cookie_name', $this
      ->t('Invalid cookie name, please remove any special characters and try again.'));
  }
}