You are here

public function ExternalLinkPopupForm::validateForm in External Link Pop-up 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/ExternalLinkPopupForm.php, line 110

Class

ExternalLinkPopupForm
Form handler for the External Link Pop-up add and edit forms.

Namespace

Drupal\external_link_popup\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $domains = trim($form_state
    ->getValue('domains'));
  if ($domains != '*' && !preg_match('/^([^\\s\\/\\,+]+[^\\S\\n]*\\n)*([^\\s\\/\\,+]+)$/', $domains)) {
    $form_state
      ->setErrorByName('domains', $this
      ->t('Please match the requested format.'));
  }
  else {
    $form_state
      ->setValue('domains', $domains);
  }
}