You are here

public function Single::validateForm in Siteimprove 8

Form validation handler.

If the plugin needs to perform a form validation, override this function.

Parameters

array $form: Form to validate.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Overrides SiteimproveDomainBase::validateForm

File

src/Plugin/SiteimproveDomain/Single.php, line 71

Class

Single
Provides simple plugin instance of Siteimprove Domain settings.

Namespace

Drupal\siteimprove\Plugin\SiteimproveDomain

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $value = $form_state
    ->getValue('single_domain');
  if (!preg_match('/^(https?:\\/\\/)?([a-zA-Z0-9][a-zA-Z0-9-_]*\\.)*[a-zA-Z0-9]*[a-zA-Z0-9-_]*[[a-zA-Z0-9]+(:\\d+)?$/', $value)) {
    $form_state
      ->setErrorByName('single_domain', $this
      ->t('Only use valid domain names in this field - no trailing slash, no trailing whitespace.'));
  }
}