You are here

public function SimplesitemapCustomLinksForm::submitForm in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/SimplesitemapCustomLinksForm.php \Drupal\simple_sitemap\Form\SimplesitemapCustomLinksForm::submitForm()

Form submission 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 ConfigFormBase::submitForm

File

src/Form/SimplesitemapCustomLinksForm.php, line 152

Class

SimplesitemapCustomLinksForm
Class SimplesitemapCustomLinksForm @package Drupal\simple_sitemap\Form

Namespace

Drupal\simple_sitemap\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->generator
    ->setVariants(TRUE)
    ->removeCustomLinks();
  if (!empty($variants = $form_state
    ->getValue('variants')) && !empty($links = $form_state
    ->getValue('custom_links'))) {
    $this->generator
      ->setVariants(array_values($variants));
    foreach ($this
      ->stringToCustomLinks($links) as $link_config) {
      $this->generator
        ->addCustomLink($link_config['path'], $link_config);
    }
  }
  $this->generator
    ->saveSetting('custom_links_include_images', (bool) $form_state
    ->getValue('include_images'));
  parent::submitForm($form, $form_state);

  // Regenerate sitemaps according to user setting.
  if ($form_state
    ->getValue('simple_sitemap_regenerate_now')) {
    $this->generator
      ->setVariants(TRUE)
      ->rebuildQueue()
      ->generateSitemap();
  }
}