You are here

protected function SitemapGeneratorBase::getIndexXml in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 4.x src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php \Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorBase::getIndexXml()

Parameters

array $chunk_info:

Return value

string

1 call to SitemapGeneratorBase::getIndexXml()
SitemapGeneratorBase::generateIndex in src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php

File

src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php, line 150

Class

SitemapGeneratorBase
Class SitemapGeneratorBase @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator

Code

protected function getIndexXml(array $chunk_info) {
  $this->writer
    ->openMemory();
  $this->writer
    ->setIndent(TRUE);
  $this->writer
    ->startSitemapDocument();

  // Add the XML stylesheet to document if enabled.
  if ($this->settings['xsl']) {
    $this->writer
      ->writeXsl();
  }
  $this->writer
    ->writeGeneratedBy();
  $this->writer
    ->startElement('sitemapindex');

  // Add attributes to document.
  $attributes = self::$indexAttributes;
  $sitemap_variant = $this->sitemapVariant;
  $this->moduleHandler
    ->alter('simple_sitemap_index_attributes', $attributes, $sitemap_variant);
  foreach ($attributes as $name => $value) {
    $this->writer
      ->writeAttribute($name, $value);
  }

  // Add sitemap chunk locations to document.
  foreach ($chunk_info as $chunk_data) {
    $this->writer
      ->startElement('sitemap');
    $this->writer
      ->writeElement('loc', $this
      ->getSitemapUrl($chunk_data->delta));
    $this->writer
      ->writeElement('lastmod', date('c', $chunk_data->sitemap_created));
    $this->writer
      ->endElement();
  }
  $this->writer
    ->endElement();
  $this->writer
    ->endDocument();
  return $this->writer
    ->outputMemory();
}