You are here

public function SitemapGenerator::generate_sitemap in Simple XML sitemap 8

Generates and returns the sitemap.

Parameters

int $max_links: This number dictates how many sitemap chunks are to be created.

Return value

array $sitemaps.

File

src/SitemapGenerator.php, line 66
Contains \Drupal\simplesitemap\SitemapGenerator.

Class

SitemapGenerator
SitemapGenerator class.

Namespace

Drupal\simplesitemap

Code

public function generate_sitemap($max_links = NULL) {
  $this
    ->generate_custom_paths();
  $this
    ->generate_entity_paths();
  $sitemaps = array();

  // Create sitemap chunks according to the max_links setting.
  if (!empty($max_links) && count($this->links) > 0) {
    foreach (array_chunk($this->links, $max_links) as $sitemap_id => $sitemap_links) {
      $sitemaps[] = (object) [
        'sitemap_string' => $this
          ->generate_sitemap_chunk($sitemap_links),
        'sitemap_created' => REQUEST_TIME,
      ];
    }
  }
  else {
    $sitemaps[] = (object) [
      'sitemap_string' => $this
        ->generate_sitemap_chunk($this->links),
      'sitemap_created' => REQUEST_TIME,
    ];
  }
  return $sitemaps;
}