You are here

public function XmlSitemapWriter::writeXsl in XML sitemap 8

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

Adds the XML stylesheet to the XML page.

1 call to XmlSitemapWriter::writeXsl()
XmlSitemapWriter::startDocument in src/XmlSitemapWriter.php
Starts an XML document.

File

src/XmlSitemapWriter.php, line 125

Class

XmlSitemapWriter
Extended class for writing XML sitemap files.

Namespace

Drupal\xmlsitemap

Code

public function writeXsl() {
  $xls_url = Url::fromRoute('xmlsitemap.sitemap_xsl')
    ->toString();
  $settings = \Drupal::config('language.negotiation');
  if ($settings) {
    $url_settings = $settings
      ->get('url');
    if (isset($url_settings['source']) && $url_settings['source'] == 'domain') {
      $scheme = \Drupal::request()
        ->getScheme();
      $context = $this->sitemap
        ->getContext();
      $base_url = $scheme . '://' . $url_settings['domains'][$context['language']];
      $xls_url = Url::fromRoute('xmlsitemap.sitemap_xsl');
      $xls_url = $base_url . '/' . $xls_url
        ->getInternalPath();
    }
  }
  $this
    ->writePi('xml-stylesheet', 'type="text/xsl" href="' . $xls_url . '"');
  $this
    ->writeRaw(PHP_EOL);
}