SimplesitemapController.php 860 Bytes
Newer Older
Pawel G's avatar
Pawel G committed
1 2 3 4 5 6 7 8
<?php
/**
 * @file
 * Contains \Drupal\simplesitemap\Controller\SimplesitemapController.
 */

namespace Drupal\simplesitemap\Controller;

9
use Drupal\Core\Cache\CacheableResponse;
Pawel G's avatar
Pawel G committed
10
use Symfony\Component\HttpFoundation\Response;
11
use Drupal\simplesitemap\Simplesitemap;
Pawel G's avatar
Pawel G committed
12 13 14 15 16 17 18

/**
 * SimplesitemapController.
 */
class SimplesitemapController {

  /**
19
   * Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.
20 21 22 23 24 25
   *
   * @param int $sitemap_id
   *  Id of the sitemap chunk.
   *
   * @return object Response
   *  Returns an XML response.
Pawel G's avatar
Pawel G committed
26
   */
27
  public function get_sitemap($sitemap_id = NULL) {
28
    $sitemap = new Simplesitemap;
29
    $output = $sitemap->get_sitemap($sitemap_id);
Pawel G's avatar
Pawel G committed
30

31
    // Display sitemap with correct xml header.
32
    return new CacheableResponse($output, Response::HTTP_OK, array('content-type' => 'application/xml'));
Pawel G's avatar
Pawel G committed
33 34
  }
}