/**
  * {@inheritdoc}
  */
 public function __construct(XmlSitemapInterface $sitemap, $page = 'index')
 {
     parent::__construct($sitemap, 'index');
 }
 /**
  * {@inheritdoc}
  */
 public function generateChunk(XmlSitemapInterface $sitemap, XmlSitemapWriter $writer, $chunk)
 {
     $lastmod_format = $this->config->get('lastmod_format');
     $url_options = $sitemap->uri['options'];
     $url_options += array('absolute' => TRUE, 'xmlsitemap_base_url' => $this->state->get('xmlsitemap_base_url'), 'language' => $this->languageManager->getDefaultLanguage(), 'alias' => $this->config->get('prefetch_aliases'));
     $last_url = '';
     $link_count = 0;
     $query = db_select('xmlsitemap', 'x');
     $query->fields('x', array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
     $query->condition('x.access', 1);
     $query->condition('x.status', 1);
     $query->orderBy('x.language', 'DESC');
     $query->orderBy('x.loc');
     $query->addTag('xmlsitemap_generate');
     $query->addMetaData('sitemap', $sitemap);
     $offset = max($chunk - 1, 0) * xmlsitemap_get_chunk_size();
     $limit = xmlsitemap_get_chunk_size();
     $query->range($offset, $limit);
     $links = $query->execute();
     while ($link = $links->fetchAssoc()) {
         $link['language'] = $link['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED ? xmlsitemap_language_load($link['language']) : $url_options['language'];
         if ($url_options['alias']) {
             $link['loc'] = $this->getPathAlias($link['loc'], $link['language']->getId());
         }
         if ($url_options['base_url']) {
             $link['loc'] = rtrim($url_options['base_url'], '/') . '/' . ltrim($link['loc'], '/');
         }
         $link_options = array('language' => $link['language'], 'xmlsitemap_link' => $link, 'xmlsitemap_sitemap' => $sitemap);
         // @todo Add a separate hook_xmlsitemap_link_url_alter() here?
         $link['loc'] = empty($link['loc']) ? '<front>' : $link['loc'];
         $link_url = Url::fromUri($link['loc'], [], $link_options + $url_options)->toString();
         // Skip this link if it was a duplicate of the last one.
         // @todo Figure out a way to do this before generation so we can report
         // back to the user about this.
         if ($link_url == $last_url) {
             continue;
         } else {
             $last_url = $link_url;
             // Keep track of the total number of links written.
             $link_count++;
         }
         $element = array();
         $element['loc'] = $link_url;
         if ($link['lastmod']) {
             $element['lastmod'] = gmdate($lastmod_format, $link['lastmod']);
             // If the link has a lastmod value, update the changefreq so that links
             // with a short changefreq but updated two years ago show decay.
             // We use abs() here just incase items were created on this same cron
             // run because lastmod would be greater than REQUEST_TIME.
             $link['changefreq'] = (abs(REQUEST_TIME - $link['lastmod']) + $link['changefreq']) / 2;
         }
         if ($link['changefreq']) {
             $element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq']);
         }
         if (isset($link['priority']) && $link['priority'] != 0.5) {
             // Don't output the priority value for links that have 0.5 priority.
             // This is the default 'assumed' value if priority is not included as
             // per the sitemaps.org specification.
             $element['priority'] = number_format($link['priority'], 1);
         }
         $writer->writeSitemapElement('url', $element);
     }
     return $link_count;
 }