- Open on Drupal.org →Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - Open on Drupal.org →Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass
Hi,
I am using this module on my site together with the Simple XML Sitemap module (simple_sitemap) and also the Domain Simple Sitemap module (domain_simple_sitemap) to generate a sitemap for my project for each domain.
The sitemaps (sitemap.xml) contain links in languages that are disabled for that domain via this module (Domain Language Access).
It would be nice if there is a way to remove items from a sitemap if the language is disable via Domain Language Access.
I have created a workaround for myself that does this in a custom module:
/**
* Implements hook_simple_sitemap_links_alter().
*
* Alter sitemap generating:
* Remove language links if language is not activated on the domain.
*/
function mymodule_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
$domain_languages = _mymodule_get_domain_languages($sitemap_variant);
foreach ($links as $key => $link) {
// Remove item from sitemap if the items language is not in the domains languages.
if (!in_array($link['langcode'], $domain_languages)) {
unset($links[$key]);
continue;
}
// Remove alternate urls if its language is not in the domains languages.
if (isset($link['alternate_urls']) && !empty($link['alternate_urls'])) {
foreach ($link['alternate_urls'] as $langcode => $alternate_url) {
if (!in_array($langcode, $domain_languages)) {
unset($links[$key]['alternate_urls'][$langcode]);
}
}
}
}
}
/**
* Get an array of language codes activated for a domain.
*
* @param string $domain_key
* Domain machine name.
*
* @return array
* An array of language codes that are enabled for the domain.
*/
function _mymodule_get_domain_languages($domain_key) {
$config = \Drupal::config('domain.language.' . $domain_key . '.language.negotiation')->getRawData();
if (isset($config['languages'])) {
if (isset($config['languages']['***LANGUAGE_site_default***'])) {
unset($config['languages']['***LANGUAGE_site_default***']);
}
return $config['languages'];
}
$languages = [];
$languages[] = \Drupal::languageManager()->getDefaultLanguage()->getId();
return $languages;
}
Needs review
2.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.