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

namespace Drupal\simplesitemap\Controller;

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

/**
 * SimplesitemapController.
 */
class SimplesitemapController {

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

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.
Pawel G's avatar
Pawel G committed
32 33 34
    return new Response($output, Response::HTTP_OK, array('content-type' => 'application/xml'));
  }
}