Skip to content

Instantly share code, notes, and snippets.

@jnous
Last active December 2, 2015 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnous/61f27437a92937acd8fe to your computer and use it in GitHub Desktop.
Save jnous/61f27437a92937acd8fe to your computer and use it in GitHub Desktop.
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