hook_language_switch_links_alter

hook_language_switch_links_alter(array &$links, $type, $path)

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

$links: Nested array of links keyed by language code.

$type: The language type the links will switch.

$path: The current path.

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Language/language.api.php, line 172
Hooks provided by the base system for language support.

Code

function hook_language_switch_links_alter(array &$links, $type, $path) {
  $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';
    }
  }
}
doc_Drupal
2016-10-29 09:18:18
Comments
Leave a Comment

Please login to continue.