public function SitemapGenerator::generateSitemapIndex in Simple XML sitemap 8.2
Generates and returns the sitemap index for all sitemap chunks.
Parameters
array $chunk_info: Array containing chunk creation timestamps keyed by chunk ID.
Return value
string sitemap index
File
- src/
SitemapGenerator.php, line 155
Class
- SitemapGenerator
- Class SitemapGenerator @package Drupal\simple_sitemap
Namespace
Drupal\simple_sitemapCode
public function generateSitemapIndex(array $chunk_info) {
$this->writer
->openMemory();
$this->writer
->setIndent(TRUE);
$this->writer
->startDocument(self::XML_VERSION, self::ENCODING);
$this->writer
->writeComment(self::GENERATED_BY);
$this->writer
->startElement('sitemapindex');
// Add attributes to document.
$this->moduleHandler
->alter('simple_sitemap_index_attributes', self::$indexAttributes);
foreach (self::$indexAttributes as $name => $value) {
$this->writer
->writeAttribute($name, $value);
}
// Add sitemap locations to document.
foreach ($chunk_info as $chunk_id => $chunk_data) {
$this->writer
->startElement('sitemap');
$this->writer
->writeElement('loc', $this
->getCustomBaseUrl() . '/sitemaps/' . $chunk_id . '/' . 'sitemap.xml');
$this->writer
->writeElement('lastmod', date_iso8601($chunk_data->sitemap_created));
$this->writer
->endElement();
}
$this->writer
->endElement();
$this->writer
->endDocument();
return $this->writer
->outputMemory();
}