You are here

public function Simplesitemap::generateSitemap in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 src/Simplesitemap.php \Drupal\simple_sitemap\Simplesitemap::generateSitemap()

Generates the XML sitemap and saves it to the db.

Parameters

string $from: Can be 'form', 'backend', 'drush' or 'nobatch'. This decides how the batch process is to be run.

Return value

bool|\Drupal\simple_sitemap\Simplesitemap

File

src/Simplesitemap.php, line 236

Class

Simplesitemap
Class Simplesitemap @package Drupal\simple_sitemap

Namespace

Drupal\simple_sitemap

Code

public function generateSitemap($from = 'form') {
  $this->batch
    ->setBatchSettings([
    'base_url' => $this
      ->getSetting('base_url', ''),
    'batch_process_limit' => $this
      ->getSetting('batch_process_limit', NULL),
    'max_links' => $this
      ->getSetting('max_links', 2000),
    'skip_untranslated' => $this
      ->getSetting('skip_untranslated', FALSE),
    'remove_duplicates' => $this
      ->getSetting('remove_duplicates', TRUE),
    'excluded_languages' => $this
      ->getSetting('excluded_languages', []),
    'from' => $from,
  ]);
  $plugins = $this->urlGeneratorManager
    ->getDefinitions();
  usort($plugins, function ($a, $b) {
    return $a['weight'] - $b['weight'];
  });
  foreach ($plugins as $plugin) {
    if ($plugin['enabled']) {
      if (!empty($plugin['settings']['instantiate_for_each_data_set'])) {
        foreach ($this->urlGeneratorManager
          ->createInstance($plugin['id'])
          ->getDataSets() as $data_sets) {
          $this->batch
            ->addOperation($plugin['id'], $data_sets);
        }
      }
      else {
        $this->batch
          ->addOperation($plugin['id']);
      }
    }
  }
  $success = $this->batch
    ->start();
  return $from === 'nobatch' ? $this : $success;
}