Commit 75017cd1 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #3107818 by gbyte.co, manuel.adan: Treat multilingual site with no URL...

Issue #3107818 by gbyte.co, manuel.adan: Treat multilingual site with no URL detection as monolingual
parent 0dc11015
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator; namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase; use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
...@@ -345,4 +346,17 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -345,4 +346,17 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
return $url->toString(); return $url->toString();
} }
/**
* @return bool
*/
public static function isMultilingualSitemap() {
$has_multiple_indexable_languages = count(
array_diff_key(\Drupal::languageManager()->getLanguages(),
\Drupal::service('simple_sitemap.generator')->getSetting('excluded_languages'))
) > 1;
return $has_multiple_indexable_languages
&& \Drupal::service('language_negotiator')->isNegotiationMethodEnabled(LanguageNegotiationUrl::METHOD_ID);
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator; namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Url; use Drupal\Core\Url;
...@@ -45,6 +46,11 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase { ...@@ -45,6 +46,11 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
*/ */
protected $entityHelper; protected $entityHelper;
/**
* @var bool
*/
protected $isMultilingualSitemap;
/** /**
* UrlGeneratorBase constructor. * UrlGeneratorBase constructor.
* @param array $configuration * @param array $configuration
...@@ -72,6 +78,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase { ...@@ -72,6 +78,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->anonUser = new AnonymousUserSession(); $this->anonUser = new AnonymousUserSession();
$this->entityHelper = $entityHelper; $this->entityHelper = $entityHelper;
$this->isMultilingualSitemap = SitemapGeneratorBase::isMultilingualSitemap();
} }
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
...@@ -97,8 +104,9 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase { ...@@ -97,8 +104,9 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
protected function getUrlVariants(array $path_data, Url $url_object) { protected function getUrlVariants(array $path_data, Url $url_object) {
$url_variants = []; $url_variants = [];
if (!$url_object->isRouted()) { if (!$this->isMultilingualSitemap || !$url_object->isRouted()) {
// Not a routed URL, including only default variant.
// Not a routed URL or URL language negotiation disabled: Including only default variant.
$alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object); $alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object);
} }
elseif ($this->settings['skip_untranslated'] elseif ($this->settings['skip_untranslated']
...@@ -109,7 +117,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase { ...@@ -109,7 +117,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
if (isset($translation_languages[Language::LANGCODE_NOT_SPECIFIED]) if (isset($translation_languages[Language::LANGCODE_NOT_SPECIFIED])
|| isset($translation_languages[Language::LANGCODE_NOT_APPLICABLE])) { || isset($translation_languages[Language::LANGCODE_NOT_APPLICABLE])) {
// Content entity's language is unknown, including only default variant. // Content entity's language is unknown: Including only default variant.
$alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object); $alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object);
} }
else { else {
...@@ -228,4 +236,5 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase { ...@@ -228,4 +236,5 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
return $image_data; return $image_data;
} }
} }
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