You are here

function xmlsitemap_link_bundle_settings_form_submit in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_link_bundle_settings_form_submit()
  2. 6.2 xmlsitemap.module \xmlsitemap_link_bundle_settings_form_submit()
  3. 7.2 xmlsitemap.module \xmlsitemap_link_bundle_settings_form_submit()

Submit callback for link bundle settings.

File

./xmlsitemap.module, line 1280
xmlsitemap XML sitemap

Code

function xmlsitemap_link_bundle_settings_form_submit($form, &$form_state) {
  $entity = $form['xmlsitemap']['#entity'];
  $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_link_bundle_settings_save($entity, $bundle, $form_state
    ->getValue('xmlsitemap'));
  $entity_info = $form['xmlsitemap']['#entity_info'];
  if (!empty($form['xmlsitemap']['#show_message'])) {
    \Drupal::messenger()
      ->addStatus(t('XML sitemap settings for the @bundle-label %bundle have been saved.', [
      '@bundle-label' => mb_strtolower($entity_info['bundle label']),
      '%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 variables in-case this form
  // also uses system_settings_form().
  $form_state
    ->unsetValue('xmlsitemap');
}