public function SimplesitemapController::getSitemap in Simple XML sitemap 8.2
Same name and namespace in other branches
- 8.3 src/Controller/SimplesitemapController.php \Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap()
- 4.x src/Controller/SimpleSitemapController.php \Drupal\simple_sitemap\Controller\SimpleSitemapController::getSitemap()
Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file. Caches the response in case of expected output, prevents caching otherwise.
Parameters
int $chunk_id: Optional ID of the sitemap chunk. If none provided, the first chunk or the sitemap index is fetched.
Return value
object Returns an XML response.
Throws
1 string reference to 'SimplesitemapController::getSitemap'
File
- src/
Controller/ SimplesitemapController.php, line 62
Class
- SimplesitemapController
- Class SimplesitemapController @package Drupal\simple_sitemap\Controller
Namespace
Drupal\simple_sitemap\ControllerCode
public function getSitemap($chunk_id = NULL) {
$output = $this->generator
->getSitemap($chunk_id);
if (!$output) {
$this->cacheKillSwitch
->trigger();
throw new NotFoundHttpException();
}
// Display sitemap with correct XML header.
$response = new CacheableResponse($output, Response::HTTP_OK, [
'content-type' => 'application/xml',
'X-Robots-Tag' => 'noindex',
]);
// Cache output.
$meta_data = $response
->getCacheableMetadata();
$meta_data
->addCacheTags([
'simple_sitemap',
]);
return $response;
}