Skip to content
Snippets Groups Projects

Add 'is-active' class to language block links of current language

All threads resolved!
1 file
+ 5
0
Compare changes
  • Side-by-side
  • Inline
@@ -100,8 +100,13 @@ public function build() {
$url = Url::fromRouteMatch($route_match);
}
$links = $this->languageManager->getLanguageSwitchLinks($type, $url);
$current_language_code = $this->languageManager->getCurrentLanguage()->getId();
if (isset($links->links)) {
// Add the active state.
if (isset($links->links[$current_language_code])) {
$links->links[$current_language_code]['attributes']['class'][] = 'is-active';
}
$build = [
'#theme' => 'links__language_block',
'#links' => $links->links,
Loading