You are here

public function Simplesitemap::getSitemap in Simple XML sitemap 8.3

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

Returns a sitemap variant, its index, or its requested chunk.

Parameters

int|null $delta: Optional delta of the chunk.

Return value

string|false If no chunk delta is provided, either the sitemap variant is returned, or its index in case of a chunked sitemap. If a chunk delta is provided, the relevant chunk is returned. Returns false if the sitemap variant is not retrievable from the database.

File

src/Simplesitemap.php, line 260

Class

Simplesitemap
Class Simplesitemap @package Drupal\simple_sitemap

Namespace

Drupal\simple_sitemap

Code

public function getSitemap($delta = NULL) {
  $chunk_info = $this
    ->fetchSitemapVariantInfo();
  if (empty($delta) || !isset($chunk_info[$delta])) {
    if (isset($chunk_info[SitemapGeneratorBase::INDEX_DELTA])) {

      // Return sitemap index if one exists.
      return $this
        ->fetchSitemapChunk($chunk_info[SitemapGeneratorBase::INDEX_DELTA]->id)->sitemap_string;
    }

    // Return sitemap chunk if there is only one chunk.
    return isset($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA]) ? $this
      ->fetchSitemapChunk($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA]->id)->sitemap_string : FALSE;
  }

  // Return specific sitemap chunk.
  return $this
    ->fetchSitemapChunk($chunk_info[$delta]->id)->sitemap_string;
}