You are here

public function XmlSitemapWriter::writeXsl in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 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);
}