You are here

public function SimplesitemapEntitiesForm::submitForm in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 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 113

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)) {
          $this->generator
            ->setBundleSettings($entity_type_id, $entity_type_id, [
            'index' => TRUE,
            'priority' => $values[$entity_type_id . '_simple_sitemap_priority'],
            'changefreq' => $values[$entity_type_id . '_simple_sitemap_changefreq'],
            'include_images' => $values[$entity_type_id . '_simple_sitemap_include_images'],
          ]);
        }
      }
      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
      ->generateSitemap();
  }
}