function disable_language_simple_sitemap_links_alter in Disable language 8
Implements hook_simple_sitemap_links_alter().
File
- ./
disable_language.module, line 131 - Contains disable_language.module.
Code
function disable_language_simple_sitemap_links_alter(array &$links) {
$disabledLanguages = \Drupal::service('disable_language.disable_language_manager')
->getDisabledLanguages();
if (!empty($disabledLanguages)) {
$disabledLanguagesLangCodes = array_keys($disabledLanguages);
// Remove the urls for disabled languages.
foreach ($links as $key => $link) {
// Remove 'loc' URL if it points to a disabled language.
if (in_array($link['langcode'], $disabledLanguagesLangCodes)) {
unset($links[$key]);
}
else {
if (isset($link['alternate_urls'])) {
foreach ($link['alternate_urls'] as $langcode => $alternate_url) {
if (in_array($langcode, $disabledLanguagesLangCodes)) {
unset($links[$key]['alternate_urls'][$langcode]);
}
}
}
}
}
}
}