Commit ccdc97df authored by gbyte.co's avatar gbyte.co

Return 404 if visiting sitemap.xml and sitemap has not been generated yet

parent ab1ce42f
...@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheableResponse; ...@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* SimplesitemapController. * SimplesitemapController.
...@@ -36,12 +37,16 @@ class SimplesitemapController extends ControllerBase { ...@@ -36,12 +37,16 @@ class SimplesitemapController extends ControllerBase {
* Optional ID of the sitemap chunk. If none provided, the first chunk or * Optional ID of the sitemap chunk. If none provided, the first chunk or
* the sitemap index is fetched. * the sitemap index is fetched.
* *
* @throws NotFoundHttpException
*
* @return object Response * @return object Response
* Returns an XML response. * Returns an XML response.
*/ */
public function getSitemap($chunk_id = NULL) { public function getSitemap($chunk_id = NULL) {
$output = $this->generator->getSitemap($chunk_id); $output = $this->generator->getSitemap($chunk_id);
$output = !$output ? '' : $output; if (!$output) {
throw new NotFoundHttpException();
}
// Display sitemap with correct xml header. // Display sitemap with correct xml header.
$response = new CacheableResponse($output, Response::HTTP_OK, ['content-type' => 'application/xml']); $response = new CacheableResponse($output, Response::HTTP_OK, ['content-type' => 'application/xml']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment