Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal 8 implementation of hook_language_switch_links_alter that replaces links in language switcher block with links to front page.
<?php
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
/**
* Implements hook_language_switch_links_alter().
*
* Replaces links in language switcher block with links to front page.
*/
function MYMODULE_language_switch_links_alter(array &$links, $type, $path) {
if ($type == LanguageInterface::TYPE_INTERFACE) {
$front = new Url('<front>');
foreach ($links as &$link) {
$link['url'] = $front;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment