Commit 6685dd03 authored by gbyte.co's avatar gbyte.co

Code cleanup

parent a2318abc
name: 'Simple XML Sitemap' name: 'Simple XML Sitemap'
type: module type: module
description: 'Creates a standard conform XML sitemap of your content.' description: 'Creates a standard conform hreflang XML sitemap of your content.'
configure: simple_sitemap.settings configure: simple_sitemap.settings
package: SEO package: SEO
core: 8.x core: 8.x
...@@ -35,15 +35,16 @@ class SitemapGenerator { ...@@ -35,15 +35,16 @@ class SitemapGenerator {
*/ */
protected $db; protected $db;
/** /**
* @var \Drupal\Core\Extension\ModuleHandler * @var \Drupal\Core\Language\LanguageManagerInterface
*/ */
protected $moduleHandler; protected $languageManager;
/** /**
* @var string * @var \Drupal\Core\Extension\ModuleHandler
*/ */
protected $defaultLanguageId; protected $moduleHandler;
/** /**
* @var string * @var string
...@@ -79,8 +80,19 @@ class SitemapGenerator { ...@@ -79,8 +80,19 @@ class SitemapGenerator {
$this->entityHelper = $entityHelper; $this->entityHelper = $entityHelper;
$this->db = $database; $this->db = $database;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
$this->defaultLanguageId = $language_manager->getDefaultLanguage()->getId(); $this->languageManager = $language_manager;
$this->isHreflangSitemap = count($language_manager->getLanguages()) > 1; $this->setIsHreflangSitemap();
}
protected function setIsHreflangSitemap() {
$this->isHreflangSitemap = count($this->languageManager->getLanguages()) > 1;
}
/**
* @return bool
*/
public function isHreflangSitemap() {
return $this->isHreflangSitemap;
} }
/** /**
...@@ -108,7 +120,7 @@ class SitemapGenerator { ...@@ -108,7 +120,7 @@ class SitemapGenerator {
$this->batch->setBatchInfo([ $this->batch->setBatchInfo([
'from' => $this->generateFrom, 'from' => $this->generateFrom,
'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit')) 'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit'))
? $this->generator->getSetting('batch_process_limit') : NULL, ? $this->generator->getSetting('batch_process_limit') : NULL,
'max_links' => $this->generator->getSetting('max_links', 2000), 'max_links' => $this->generator->getSetting('max_links', 2000),
'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE), 'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE),
'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE), 'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE),
...@@ -248,7 +260,8 @@ class SitemapGenerator { ...@@ -248,7 +260,8 @@ class SitemapGenerator {
$writer->writeComment(self::GENERATED_BY); $writer->writeComment(self::GENERATED_BY);
$writer->startElement('urlset'); $writer->startElement('urlset');
$writer->writeAttribute('xmlns', self::XMLNS); $writer->writeAttribute('xmlns', self::XMLNS);
if ($this->isHreflangSitemap) {
if ($this->isHreflangSitemap()) {
$writer->writeAttribute('xmlns:xhtml', self::XMLNS_XHTML); $writer->writeAttribute('xmlns:xhtml', self::XMLNS_XHTML);
} }
...@@ -261,7 +274,7 @@ class SitemapGenerator { ...@@ -261,7 +274,7 @@ class SitemapGenerator {
// If more than one language is enabled, add all translation variant URLs // If more than one language is enabled, add all translation variant URLs
// as alternate links to this location turning the sitemap into a hreflang // as alternate links to this location turning the sitemap into a hreflang
// sitemap. // sitemap.
if ($this->isHreflangSitemap) { if ($this->isHreflangSitemap()) {
foreach ($link['alternate_urls'] as $language_id => $alternate_url) { foreach ($link['alternate_urls'] as $language_id => $alternate_url) {
$writer->startElement('xhtml:link'); $writer->startElement('xhtml:link');
$writer->writeAttribute('rel', 'alternate'); $writer->writeAttribute('rel', 'alternate');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment