Language switcher footer

This commit is contained in:
David Valdez 2019-01-21 23:48:06 -06:00
parent 7184d9cfc3
commit be9d0e8083
6 changed files with 62 additions and 19 deletions

View file

@ -1,25 +1,14 @@
<?php
use \Drupal\Core\Url;
use \Drupal\block\Entity\Block;
/**
* Implements hook_preprocess_block__system_menu_block__main().
* Implements hook_preprocess_region__footer().
*/
function agarica_preprocess_block__system_menu_block__main(&$variables) {
$pathMatcher = \Drupal::service('path.matcher');
$languageManager = \Drupal::service('language_manager');
$route_name = $pathMatcher->isFrontPage() ? '<front>' : '<current>';
$type = 'language_interface';
$language_links = $languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
$variables['language'] = [];
foreach ($language_links->links as $langcode => $link) {
$language_links->links[$langcode]['attributes']['class'][] = 'navbar-item';
$language_links->links[$langcode]['title'] = $langcode;
}
$variables['language'] = [
'#theme' => 'links__language_block',
'#links' => $language_links->links,
'#set_active_class' => TRUE,
];
function agarica_preprocess_region__footer(&$variables) {
$block = Block::load('languageswitcher');
$block_content = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
$variables['language_switcher'] = $block_content;
}