function flags_language_language_switch_links_alter in Flags 8
Implements hook_language_switch_links_alter().
Implemented to add flags to the language switcher links.
Parameters
array $links:
string $type:
string $path:
File
- flags_language/
flags_language.module, line 15
Code
function flags_language_language_switch_links_alter(array &$links, $type, $path) {
/** @var FlagMappingInterface $mapper */
$mapper = \Drupal::service('flags.mapping.language');
foreach ($links as $langCode => &$link) {
$title = $link['title'];
// If title is a string, then we turn it into renderable array.
// Otherwise it probably already is a renderable array.
if (is_string($title)) {
$title = array(
'#markup' => $link['title'],
);
}
$link['title'] = array(
'flag' => array(
'#theme' => 'flags',
'#code' => $mapper
->map($langCode),
'#source' => 'language',
),
'title' => $title,
);
}
}