bootstrap_languages.module in Bootstrap Languages 8
Same filename and directory in other branches
Provides a Bootstrap dropdown button to switch between available languages.
File
bootstrap_languages.moduleView source
<?php
/**
* @file
* Provides a Bootstrap dropdown button to switch between available languages.
*/
use Drupal\Component\Utility\NestedArray;
/**
* Implements hook_theme().
*/
function bootstrap_languages_theme() {
$theme['links__bootstrap_language_block'] = [
'base hook' => 'links',
];
return $theme;
}
/**
* Implements hook_preprocess_HOOK().
*
* Preprocess for links--bootstrap-language-block.html.twig.
*/
function bootstrap_languages_preprocess_links__bootstrap_language_block(&$vars) {
$vars['current_language'] = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$vars['languages'] = [];
foreach ($vars['links'] as $lang_key => $link) {
/** @var \Drupal\Core\Url $url */
$url = $link['link']['#url'];
$url_options = NestedArray::mergeDeep($url
->getOptions(), $link['link']['#options']);
$vars['languages'][$lang_key] = $url
->setOptions($url_options);
}
}
Functions
Name | Description |
---|---|
bootstrap_languages_preprocess_links__bootstrap_language_block | Implements hook_preprocess_HOOK(). |
bootstrap_languages_theme | Implements hook_theme(). |