You are here

function xmlsitemap_get_current_chunk in XML sitemap 8

Same name and namespace in other branches
  1. 6.2 xmlsitemap.pages.inc \xmlsitemap_get_current_chunk()
  2. 7.2 xmlsitemap.pages.inc \xmlsitemap_get_current_chunk()
  3. 2.x xmlsitemap.module \xmlsitemap_get_current_chunk()

Get the sitemap chunk/page of the current request.

Parameters

\Drupal\xmlsitemap\XmlSitemapInterface $sitemap: Sitemap entity.

\Symfony\Component\HttpFoundation\Request $request: The request to use if provided, otherwise \Drupal::request() will be used.

Return value

int|string Returns current chunk of the sitemap.

1 call to xmlsitemap_get_current_chunk()
XmlSitemapController::renderSitemapXml in src/Controller/XmlSitemapController.php
Provides the sitemap in XML format.

File

./xmlsitemap.module, line 2267
xmlsitemap XML sitemap

Code

function xmlsitemap_get_current_chunk(XmlSitemapInterface $sitemap, Request $request = NULL) {
  if (!isset($request)) {
    $request = \Drupal::request();
  }

  // Check if we should display the index.
  $query = $request->query;
  $query_page = $query
    ->get('page');
  if (!isset($query_page) || !is_numeric($query_page)) {
    if ($sitemap
      ->getChunks() > 1) {
      return 'index';
    }
    else {
      return 1;
    }
  }
  else {
    return (int) $query_page;
  }
}