You are here

public function CustomContextualLinkForm::validateForm in Custom Contextual Links 8.2

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/CustomContextualLinkForm.php, line 284

Class

CustomContextualLinkForm
Class CustomContextualLinkForm.

Namespace

Drupal\ccl\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $url = $form_state
    ->getValue('link');
  if (strpos($url, '/') !== 0 && strpos($url, 'http') !== 0) {
    $form_state
      ->setErrorByName('link', $this
      ->t("Internal links need to start with a '/' and external links with 'http'"));
  }
}