You are here

public function ShurlySettingsForm::validateForm in ShURLy 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/ShurlySettingsForm.php, line 199

Class

ShurlySettingsForm
ShurlySettingsForm.

Namespace

Drupal\shurly\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $custom_base_url = trim($form_state
    ->getValue('shurly_base'));

  // We need to deal with an empty value here. But then wie don't need to validate the url.
  if (!empty($custom_base_url) && !UrlHelper::isValid($custom_base_url, $absolute = TRUE)) {
    $form_state
      ->setErrorByName('shurly_base', t('The base URL is not valid.'));
  }
}