You are here

public function AdminSettingsForm::validateForm in Googalytics - Google Analytics 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/AdminSettingsForm.php, line 209

Class

AdminSettingsForm
Form for editing Google Analytics settings.

Namespace

Drupal\ga\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $property = $form_state
    ->getValue('tracking_id');
  if (!empty($property) && !preg_match('/^UA-\\d+-\\d+$/', $property)) {
    $form_state
      ->setErrorByName('tracking_id', $this
      ->t('The provided Tracking ID is not valid.'));
  }
}