You are here

public function SimpleSitemap::isMultilingual in Simple XML sitemap 4.x

Determines if the sitemap is to be a multilingual sitemap based on several factors.

A hreflang/multilingual sitemap is only wanted if there are indexable languages available and if there is a language negotiation method enabled that is based on URL discovery. Any other language negotiation methods should be irrelevant, as a sitemap can only use URLs to guide to the correct language.

Return value

bool

Overrides SimpleSitemapInterface::isMultilingual

See also

https://www.drupal.org/project/simple_sitemap/issues/3154570#comment-137...

File

src/Entity/SimpleSitemap.php, line 249

Class

SimpleSitemap
Defines the simple_sitemap entity.

Namespace

Drupal\simple_sitemap\Entity

Code

public function isMultilingual() : bool {
  if (!\Drupal::service('module_handler')
    ->moduleExists('language')) {
    return FALSE;
  }
  $url_negotiation_method_enabled = FALSE;
  $language_negotiator = \Drupal::service('language_negotiator');
  foreach ($language_negotiator
    ->getNegotiationMethods(LanguageInterface::TYPE_URL) as $method) {
    if ($language_negotiator
      ->isNegotiationMethodEnabled($method['id'])) {
      $url_negotiation_method_enabled = TRUE;
      break;
    }
  }
  $has_multiple_indexable_languages = count(array_diff_key(\Drupal::languageManager()
    ->getLanguages(), \Drupal::service('simple_sitemap.settings')
    ->get('excluded_languages', []))) > 1;
  return $url_negotiation_method_enabled && $has_multiple_indexable_languages;
}