You are here

public function XmlSitemapLinkBundleSettingsForm::submitForm in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 src/Form/XmlSitemapLinkBundleSettingsForm.php \Drupal\xmlsitemap\Form\XmlSitemapLinkBundleSettingsForm::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/XmlSitemapLinkBundleSettingsForm.php, line 99

Class

XmlSitemapLinkBundleSettingsForm
Configure what entities will be included in sitemap.

Namespace

Drupal\xmlsitemap\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $bundle = $form['xmlsitemap']['#bundle'];

  // Handle new bundles by fetching the proper bundle key value from the form
  // state values.
  if (empty($bundle)) {
    $entity_info = $form['xmlsitemap']['#entity_info'];
    if (isset($entity_info['bundle keys']['bundle'])) {
      $bundle_key = $entity_info['bundle keys']['bundle'];
      if ($form_state
        ->hasValue($bundle_key)) {
        $bundle = $form_state
          ->getValue($bundle_key);
        $form['xmlsitemap']['#bundle'] = $bundle;
      }
    }
  }
  $xmlsitemap = $form_state
    ->getValue('xmlsitemap');
  xmlsitemap_link_bundle_settings_save($this->entity_type, $this->bundle_type, $xmlsitemap, TRUE);
  $this->state
    ->set('xmlsitemap_regenerate_needed', TRUE);
  $entity_info = $form['xmlsitemap']['#entity_info'];
  if (!empty($form['xmlsitemap']['#show_message'])) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('XML sitemap settings for the %bundle have been saved.', [
      '%bundle' => $entity_info['bundles'][$bundle]['label'],
    ]));
  }

  // Unset the form values since we have already saved the bundle settings and
  // we don't want these values to get saved as configuration, depending on
  // how the form saves the form values.
  $form_state
    ->unsetValue('xmlsitemap');
  $form_state
    ->setRedirect('xmlsitemap.admin_settings');
  parent::submitForm($form, $form_state);
}