-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from openeuropa/OEL-1167
OEL-1167: Theme the content language switcher.
- Loading branch information
Showing
22 changed files
with
450 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
19 changes: 19 additions & 0 deletions
19
config/optional/block.block.oe_whitelabel_main_page_content.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- system | ||
theme: | ||
- oe_whitelabel | ||
id: oe_whitelabel_main_page_content | ||
theme: oe_whitelabel | ||
region: content | ||
weight: -2 | ||
provider: null | ||
plugin: system_main_block | ||
settings: | ||
id: system_main_block | ||
label: 'Main page content' | ||
label_display: '0' | ||
provider: system | ||
visibility: { } |
This file contains 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
This file contains 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
This file contains 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
7 changes: 7 additions & 0 deletions
7
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.info.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: OpenEuropa Whitelabel Multilingual | ||
type: module | ||
description: Adds additional functionality to the Multilingual module | ||
package: OpenEuropa Whitelabel Theme | ||
core_version_requirement: ^9.2 | ||
dependencies: | ||
- openeuropa:oe_multilingual |
123 changes: 123 additions & 0 deletions
123
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* OE Whitelabel theme Multilingual. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
use Drupal\Component\Utility\Html; | ||
|
||
/** | ||
* Implements hook_preprocess_links(). | ||
*/ | ||
function oe_whitelabel_multilingual_preprocess_links__oe_multilingual_content_language_block(array &$variables): void { | ||
// Generate the label for the unavailable language. | ||
/** @var \Drupal\Core\Language\LanguageInterface[] $languages */ | ||
$languages = \Drupal::service('language_manager')->getNativeLanguages(); | ||
$variables['unavailable_language'] = $languages[$variables['current_language_id']]->getName(); | ||
|
||
// Normalize the links to an array of optional languages suitable for the BCL. | ||
$variables['languages'] = []; | ||
foreach ($variables['links'] as $language_code => $link) { | ||
/** @var \Drupal\Core\Url $url */ | ||
$url = $link['link']['#url']; | ||
$href = $url | ||
->setOptions($link['link']['#options']) | ||
->setAbsolute(TRUE) | ||
->toString(); | ||
|
||
$variables['languages'][] = [ | ||
'path' => $href, | ||
'hreflang' => $language_code, | ||
'label' => $link['link']['#title'], | ||
'current' => FALSE, | ||
]; | ||
} | ||
|
||
// Add the current language to the list. | ||
/** @var \Drupal\oe_multilingual\MultilingualHelper $multilingual_helper */ | ||
$multilingual_helper = \Drupal::service('oe_multilingual.helper'); | ||
$entity = $multilingual_helper->getEntityFromCurrentRoute(); | ||
$translation = $multilingual_helper->getCurrentLanguageEntityTranslation($entity); | ||
// If we don't have a language id defined yet, the current translation wasn't | ||
// saved, so we don't add it to the list. | ||
if ($translation->language()->getId() !== 'und') { | ||
$variables['languages'][] = [ | ||
'path' => $translation->toUrl()->setAbsolute(TRUE)->toString(), | ||
'hreflang' => $translation->language()->getId(), | ||
'label' => $languages[$translation->language()->getId()]->getName(), | ||
'current' => TRUE, | ||
'icon_position' => 'before', | ||
'remove_icon_spacers' => FALSE, | ||
'icon' => [ | ||
'name' => 'check-lg', | ||
'path' => $variables['bcl_icon_path'], | ||
'size' => 'xs', | ||
'#attributes' => ['class' => ['me-2']], | ||
], | ||
]; | ||
} | ||
|
||
// Generate required ids. | ||
$variables['expandable_id'] = Html::getUniqueId('bcl-expandable'); | ||
} | ||
|
||
/** | ||
* Implements hook_preprocess_links__language_block(). | ||
*/ | ||
function oe_whitelabel_multilingual_preprocess_links__language_block(&$variables) { | ||
$currentLanguage = \Drupal::languageManager()->getCurrentLanguage(); | ||
$current_language_id = $currentLanguage->getId(); | ||
$language_config_storage = \Drupal::entityTypeManager()->getStorage('configurable_language'); | ||
$eu_links = []; | ||
$non_eu_links = []; | ||
|
||
foreach ($variables['links'] as $language_code => $link) { | ||
/** @var \Drupal\Core\Url $url */ | ||
$url = $link['link']['#url']; | ||
$href = $url | ||
->setOptions($link['link']['#options']) | ||
->setAbsolute(TRUE) | ||
->toString(); | ||
$label = $link['link']['#title']; | ||
|
||
$link = [ | ||
'href' => $href, | ||
'name' => $label, | ||
'id' => 'link_' . $language_code, | ||
'hreflang' => $language_code, | ||
]; | ||
|
||
if (!empty($current_language_id) && $language_code === $current_language_id) { | ||
$variables['language']['link'] = $link; | ||
$variables['language']['link']['target'] = 'languageModal'; | ||
$link['active'] = TRUE; | ||
} | ||
|
||
$language_config = $language_config_storage->load($language_code); | ||
$category = $language_config->getThirdPartySetting('oe_multilingual', 'category'); | ||
|
||
if ($category === 'eu') { | ||
$eu_links[$language_code] = $link; | ||
} | ||
else { | ||
$non_eu_links[$language_code] = $link; | ||
} | ||
} | ||
|
||
$variables['language']['modal'] = [ | ||
'id' => 'languageModal', | ||
'size' => 'fullscreen', | ||
'header' => [ | ||
'title' => t('Select your language'), | ||
'label' => t('Close'), | ||
], | ||
'eu_links' => $eu_links, | ||
'non_eu_links' => $non_eu_links, | ||
'footer' => [ | ||
'label' => t('Close'), | ||
], | ||
]; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.