You are here

public function SimplesitemapEntitiesForm::submitForm in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/SimplesitemapEntitiesForm.php \Drupal\simple_sitemap\Form\SimplesitemapEntitiesForm::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/SimplesitemapEntitiesForm.php, line 168

Class

SimplesitemapEntitiesForm
Class SimplesitemapEntitiesForm @package Drupal\simple_sitemap\Form

Namespace

Drupal\simple_sitemap\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  foreach ($values as $field_name => $value) {
    if (substr($field_name, -strlen('_enabled')) === '_enabled') {
      $entity_type_id = substr($field_name, 0, -8);
      if ($value) {
        $this->generator
          ->enableEntityType($entity_type_id);
        if ($this->entityHelper
          ->entityTypeIsAtomic($entity_type_id)) {
          foreach ($this->generator
            ->getSitemapManager()
            ->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
            if (isset($values['index_' . $variant . '_' . $entity_type_id . '_settings'])) {
              $this->generator
                ->setVariants($variant)
                ->setBundleSettings($entity_type_id, $entity_type_id, [
                'index' => (bool) $values['index_' . $variant . '_' . $entity_type_id . '_settings'],
                'priority' => $values['priority_' . $variant . '_' . $entity_type_id . '_settings'],
                'changefreq' => $values['changefreq_' . $variant . '_' . $entity_type_id . '_settings'],
                'include_images' => (bool) $values['include_images_' . $variant . '_' . $entity_type_id . '_settings'],
              ]);
            }
          }
        }
      }
      else {
        $this->generator
          ->disableEntityType($entity_type_id);
      }
    }
  }
  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();
  }
}