function hook_language_switch_links_alter
Same name in other branches
- 7.x modules/system/language.api.php \hook_language_switch_links_alter()
- 8.9.x core/lib/Drupal/Core/Language/language.api.php \hook_language_switch_links_alter()
- 10 core/lib/Drupal/Core/Language/language.api.php \hook_language_switch_links_alter()
- 11.x core/lib/Drupal/Core/Language/language.api.php \hook_language_switch_links_alter()
Perform alterations on language switcher links.
A language switcher link may need to point to a different path or use a translated link text before going through the link generator, which will just handle the path aliases.
Parameters
array $links: Nested array of links keyed by language code.
string $type: The language type the links will switch.
\Drupal\Core\Url $url: The URL the switch links will be relative to.
Related topics
1 function implements hook_language_switch_links_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- language_test_language_switch_links_alter in core/
modules/ language/ tests/ language_test/ language_test.module - Implements hook_language_switch_links_alter().
1 invocation of hook_language_switch_links_alter()
- ConfigurableLanguageManager::getLanguageSwitchLinks in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Returns the language switch links for the given language type.
File
-
core/
lib/ Drupal/ Core/ Language/ language.api.php, line 172
Code
function hook_language_switch_links_alter(array &$links, $type, \Drupal\Core\Url $url) {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->getId()])) {
foreach ($links[$language_interface->getId()] as $link) {
$link['attributes']['class'][] = 'active-language';
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.