You are here

function xmlsitemap_form_submit_flag_regenerate in XML sitemap 8

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

Submit handler; Set the regenerate needed flag if variables have changed.

This function needs to be called before system_settings_form_submit() or any calls to variable_set().

1 string reference to 'xmlsitemap_form_submit_flag_regenerate'
xmlsitemap_form_language_admin_overview_form_alter in ./xmlsitemap.module
Implements hook_form_FORM_ID_alter().

File

./xmlsitemap.module, line 1156
xmlsitemap XML sitemap

Code

function xmlsitemap_form_submit_flag_regenerate(array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  foreach ($values as $variable => $value) {
    if (\Drupal::config('xmlsitemap.settings')
      ->get($variable) == NULL) {
      $stored_value = 'not_a_variable';
    }
    else {
      $stored_value = \Drupal::config('xmlsitemap.settings')
        ->get($variable);
    }
    if (is_array($value) && !$form_state
      ->isValueEmpty('array_filter')) {
      $value = array_keys(array_filter($value));
    }
    if ($stored_value != 'not_a_variable' && $stored_value != $value) {
      \Drupal::state()
        ->set('xmlsitemap_regenerate_needed', TRUE);
      \Drupal::messenger()
        ->addWarning(t('XML sitemap settings have been modified and the files should be regenerated. You can <a href="@run-cron">run cron manually</a> to regenerate the cached files.', [
        '@run-cron' => Url::fromRoute('system.run_cron', [], [
          'query' => \Drupal::destination()
            ->getAsArray(),
        ])
          ->toString(),
      ]), FALSE);
      return;
    }
  }
}