You are here

public function XmlSitemapController::renderSitemapXsl in XML sitemap 8

Same name and namespace in other branches
  1. 2.x src/Controller/XmlSitemapController.php \Drupal\xmlsitemap\Controller\XmlSitemapController::renderSitemapXsl()

Provides the sitemap in XSL format.

Return value

\Symfony\Component\HttpFoundation\Response Response object in XSL format.

1 string reference to 'XmlSitemapController::renderSitemapXsl'
xmlsitemap.routing.yml in ./xmlsitemap.routing.yml
xmlsitemap.routing.yml

File

src/Controller/XmlSitemapController.php, line 160

Class

XmlSitemapController
Class for Xml Sitemap Controller.

Namespace

Drupal\xmlsitemap\Controller

Code

public function renderSitemapXsl() {

  // Read the XSL content from the file.
  $module_path = drupal_get_path('module', 'xmlsitemap');
  $xsl_content = file_get_contents($module_path . '/xsl/xmlsitemap.xsl');

  // Make sure the strings in the XSL content are translated properly.
  $replacements = [
    'Sitemap file' => $this
      ->t('Sitemap file'),
    'Generated by the <a href="https://www.drupal.org/project/xmlsitemap">Drupal XML sitemap module</a>.' => $this
      ->t('Generated by the <a href="@link-xmlsitemap">Drupal XML sitemap module</a>.', [
      '@link-xmlsitemap' => 'https://www.drupal.org/project/xmlsitemap',
    ]),
    'Number of sitemaps in this index' => $this
      ->t('Number of sitemaps in this index'),
    'Click on the table headers to change sorting.' => $this
      ->t('Click on the table headers to change sorting.'),
    'Sitemap URL' => $this
      ->t('Sitemap URL'),
    'Last modification date' => $this
      ->t('Last modification date'),
    'Number of URLs in this sitemap' => $this
      ->t('Number of URLs in this sitemap'),
    'URL location' => $this
      ->t('URL location'),
    'Change frequency' => $this
      ->t('Change frequency'),
    'Priority' => $this
      ->t('Priority'),
    '[jquery]' => base_path() . 'core/assets/vendor/jquery/jquery.js',
    '[jquery-tablesort]' => base_path() . $module_path . '/xsl/jquery.tablesorter.min.js',
    '[xsl-js]' => base_path() . $module_path . '/xsl/xmlsitemap.xsl.js',
    '[xsl-css]' => base_path() . $module_path . '/xsl/xmlsitemap.xsl.css',
  ];
  $xsl_content = strtr($xsl_content, $replacements);

  // Output the XSL content.
  return new Response($xsl_content, 200, [
    'Content-Type' => 'application/xml; charset=utf-8',
    'X-Robots-Tag' => 'noindex, nofollow',
  ]);
}