You are here

public function XmlSitemapEnginesSettingsForm::validateForm in XML sitemap 8

Same name and namespace in other branches
  1. 2.x xmlsitemap_engines/src/Form/XmlSitemapEnginesSettingsForm.php \Drupal\xmlsitemap_engines\Form\XmlSitemapEnginesSettingsForm::validateForm()

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

xmlsitemap_engines/src/Form/XmlSitemapEnginesSettingsForm.php, line 144

Class

XmlSitemapEnginesSettingsForm
Configure xmlsitemap engines settings for this site.

Namespace

Drupal\xmlsitemap_engines\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $custom_urls = $form_state
    ->getValue('custom_urls');
  $custom_urls = preg_split('/[\\r\\n]+/', $custom_urls, -1, PREG_SPLIT_NO_EMPTY);
  foreach ($custom_urls as $custom_url) {
    $url = xmlsitemap_engines_prepare_url($custom_url, '');
    if (!UrlHelper::isValid($url, TRUE)) {
      $form_state
        ->setErrorByName($custom_url, $this
        ->t('Invalid URL %url.', [
        '%url' => $custom_url,
      ]));
    }
  }
  $custom_urls = implode("\n", $custom_urls);
  $form_state
    ->setValue('custom_urls', $custom_urls);
}