Last active
June 14, 2022 10:01
-
-
Save NikLP/d97072946171578637815bedf9517233 to your computer and use it in GitHub Desktop.
MYTHEME.theme snippet for language switcher block in Drupal 8+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Changes the language switcher block to use country codes instead of long format country names | |
// So if the site was in English/Italian, the original switcher would show (at D9 iirc): | |
// English - Italian, and this code makes it into EN - IT (lack of correct formatting notwithstanding) | |
// This could easily be adapted to show flags etc instead I imagine. | |
/** | |
* Implements hook_preprocess_block(). | |
*/ | |
function mytheme_preprocess_block(&$variables) { | |
if ($variables['elements']['#id'] == 'languageswitcher') { | |
$links = &$variables['content']['#links']; | |
foreach ($links as $lang => $data) { | |
$variables['content']['#links'][$lang]['title'] = $lang; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment