Commit 75017cd1 authored by gbyte's avatar gbyte Committed by Pawel G

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 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;
use Drupal\Core\Url;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
......@@ -345,4 +346,17 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
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 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Url;
......@@ -45,6 +46,11 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
*/
protected $entityHelper;
/**
* @var bool
*/
protected $isMultilingualSitemap;
/**
* UrlGeneratorBase constructor.
* @param array $configuration
......@@ -72,6 +78,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
$this->entityTypeManager = $entity_type_manager;
$this->anonUser = new AnonymousUserSession();
$this->entityHelper = $entityHelper;
$this->isMultilingualSitemap = SitemapGeneratorBase::isMultilingualSitemap();
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
......@@ -97,8 +104,9 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
protected function getUrlVariants(array $path_data, Url $url_object) {
$url_variants = [];
if (!$url_object->isRouted()) {
// Not a routed URL, including only default variant.
if (!$this->isMultilingualSitemap || !$url_object->isRouted()) {
// Not a routed URL or URL language negotiation disabled: Including only default variant.
$alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object);
}
elseif ($this->settings['skip_untranslated']
......@@ -109,7 +117,7 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
if (isset($translation_languages[Language::LANGCODE_NOT_SPECIFIED])
|| 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);
}
else {
......@@ -228,4 +236,5 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
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