Commit df0ab619 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #2932885 by gbyte.co: Hreflang sitemap generated for site with single language enabled

parent fd91cd99
......@@ -148,6 +148,7 @@ class Batch {
$remove_sitemap = empty($results['chunk_count']);
if (!empty($results['generate']) || $remove_sitemap) {
\Drupal::service('simple_sitemap.sitemap_generator')
->setSettings(['excluded_languages' => \Drupal::service('simple_sitemap.generator')->getSetting('excluded_languages', [])])
->generateSitemap(!empty($results['generate']) ? $results['generate'] : [], $remove_sitemap);
}
Cache::invalidateTags(['simple_sitemap']);
......
......@@ -341,7 +341,9 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
if (count($chunk_links) == $max_links) {
// Generate sitemap.
$this->sitemapGenerator->generateSitemap($chunk_links, empty($this->getChunkCount()));
$this->sitemapGenerator
->setSettings(['excluded_languages' => $this->batchSettings['excluded_languages']])
->generateSitemap($chunk_links, empty($this->getChunkCount()));
// Update chunk count info.
$this->setChunkCount(empty($this->getChunkCount()) ? 1 : ($this->getChunkCount() + 1));
......
......@@ -2,7 +2,6 @@
namespace Drupal\simple_sitemap;
use XMLWriter;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\Language\LanguageManagerInterface;
......@@ -101,17 +100,15 @@ class SitemapGenerator {
$this->languageManager = $language_manager;
$this->time = $time;
$this->writer = $sitemapWriter;
$this->setIsHreflangSitemap();
}
protected function setIsHreflangSitemap() {
$this->isHreflangSitemap = count($this->languageManager->getLanguages()) > 1;
}
/**
* @return bool
*/
public function isHreflangSitemap() {
protected function isHreflangSitemap() {
if (NULL === $this->isHreflangSitemap) {
$this->isHreflangSitemap = count(array_diff_key($this->languageManager->getLanguages(), $this->settings['excluded_languages'])) > 1;
}
return $this->isHreflangSitemap;
}
......
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