Skip to content

Commit

Permalink
Merge pull request #94 from openeuropa/OEL-1167
Browse files Browse the repository at this point in the history
OEL-1167: Theme the content language switcher.
  • Loading branch information
drishu authored Mar 21, 2022
2 parents 93aa607 + 023a770 commit 1b1df0d
Show file tree
Hide file tree
Showing 22 changed files with 450 additions and 89 deletions.
2 changes: 1 addition & 1 deletion config/optional/block.block.oe_whitelabel_branding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ plugin: system_branding_block
settings:
id: system_branding_block
label: 'Site branding'
provider: system
label_display: '0'
provider: system
use_site_logo: true
use_site_name: true
use_site_slogan: true
Expand Down
2 changes: 1 addition & 1 deletion config/optional/block.block.oe_whitelabel_breadcrumbs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ plugin: system_breadcrumb_block
settings:
id: system_breadcrumb_block
label: Breadcrumbs
provider: system
label_display: '0'
provider: system
visibility: { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ status: true
dependencies:
module:
- oe_corporate_blocks
- oe_whitelabel_helper
theme:
- oe_whitelabel
id: oe_whitelabel_ec_corporate_footer
Expand All @@ -14,11 +15,11 @@ plugin: oe_corporate_blocks_ec_footer
settings:
id: oe_corporate_blocks_ec_footer
label: 'EC Footer block'
provider: oe_corporate_blocks
label_display: '0'
provider: oe_corporate_blocks
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: ec
negate: false
context_mapping: { }
component_library: ec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ status: true
dependencies:
module:
- oe_corporate_blocks
- oe_whitelabel_helper
theme:
- oe_whitelabel
id: oe_whitelabel_eu_corporate_footer
Expand All @@ -14,11 +15,11 @@ plugin: oe_corporate_blocks_eu_footer
settings:
id: oe_corporate_blocks_eu_footer
label: 'EU Footer block'
provider: oe_corporate_blocks
label_display: '0'
provider: oe_corporate_blocks
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: eu
negate: false
context_mapping: { }
component_library: eu
2 changes: 1 addition & 1 deletion config/optional/block.block.oe_whitelabel_eulogin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ plugin: oe_authentication_login_block
settings:
id: oe_authentication_login_block
label: 'EU Login Link Block'
provider: oe_authentication
label_display: '0'
provider: oe_authentication
visibility: { }
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ plugin: 'language_block:language_interface'
settings:
id: 'language_block:language_interface'
label: 'Language switcher (Interface text)'
provider: language
label_display: '0'
provider: language
visibility: { }
4 changes: 2 additions & 2 deletions config/optional/block.block.oe_whitelabel_local_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ dependencies:
id: oe_whitelabel_local_actions
theme: oe_whitelabel
region: content
weight: 0
weight: -4
provider: null
plugin: local_actions_block
settings:
id: local_actions_block
label: 'Primary admin actions'
provider: core
label_display: '0'
provider: core
visibility: { }
4 changes: 2 additions & 2 deletions config/optional/block.block.oe_whitelabel_local_tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ dependencies:
id: oe_whitelabel_local_tasks
theme: oe_whitelabel
region: content
weight: -1
weight: -5
provider: null
plugin: local_tasks_block
settings:
id: local_tasks_block
label: Tabs
provider: core
label_display: '0'
provider: core
primary: true
secondary: true
visibility: { }
19 changes: 19 additions & 0 deletions config/optional/block.block.oe_whitelabel_main_page_content.yml
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: { }
4 changes: 2 additions & 2 deletions config/optional/block.block.oe_whitelabel_messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ dependencies:
id: oe_whitelabel_messages
theme: oe_whitelabel
region: content
weight: -3
weight: -6
provider: null
plugin: system_messages_block
settings:
id: system_messages_block
label: 'Status messages'
provider: system
label_display: '0'
provider: system
visibility: { }
4 changes: 2 additions & 2 deletions config/optional/block.block.oe_whitelabel_neutral_footer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ plugin: oe_corporate_blocks_neutral_footer
settings:
id: oe_corporate_blocks_neutral_footer
label: 'Neutral Footer block'
provider: oe_whitelabel_helper
label_display: '0'
provider: oe_whitelabel_helper
visibility:
oe_whitelabel_helper_current_component_library:
id: oe_whitelabel_helper_current_component_library
component_library: neutral
negate: false
context_mapping: { }
component_library: neutral
4 changes: 2 additions & 2 deletions config/optional/block.block.oe_whitelabel_search_form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ plugin: whitelabel_search_block
settings:
id: whitelabel_search_block
label: 'Whitelabel Search Block'
provider: oe_whitelabel_search
label_display: '0'
provider: oe_whitelabel_search
form:
action: '#'
input:
Expand All @@ -26,7 +26,7 @@ settings:
button:
classes: ''
view_options:
enable_autocomplete: false
id: null
display: null
enable_autocomplete: false
visibility: { }
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 modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
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'),
],
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dependencies:

config_devel:
install:
- core.date_format.oe_whitelabel_starter_event_date
- core.entity_view_display.node.oe_sc_event.full
- core.entity_view_display.node.oe_sc_event.teaser
- core.date_format.oe_whitelabel_starter_event_date
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dependencies:

config_devel:
install:
- core.date_format.oe_whitelabel_starter_news_date.yml
- core.entity_view_display.node.oe_sc_news.full.yml
- core.entity_view_display.node.oe_sc_news.teaser.yml
- core.date_format.oe_whitelabel_starter_news_date
- core.entity_view_display.node.oe_sc_news.full
- core.entity_view_display.node.oe_sc_news.teaser
17 changes: 9 additions & 8 deletions oe_whitelabel.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ config_devel:
install:
- oe_whitelabel.settings
optional:
- block.block.breadcrumbs
- block.block.corporateeclogoblock
- block.block.ecfooterblock
- block.block.euloginlinkblock.yml
- block.block.languageswitcherinterfacetext
- block.block.oe_whitelabel_branding
- block.block.oe_whitelabel_breadcrumbs
- block.block.oe_whitelabel_ec_corporate_footer
- block.block.oe_whitelabel_eu_corporate_footer
- block.block.oe_whitelabel_eulogin
- block.block.oe_whitelabel_language_switcher
- block.block.oe_whitelabel_local_actions
- block.block.oe_whitelabel_local_tasks
- block.block.oe_whitelabel_main_navigation
- block.block.oe_whitelabel_main_page_content
- block.block.oe_whitelabel_messages
- block.block.oe_whitelabel_page_title
- block.block.whitelabelsearchblock
- cas.settings.yml
- block.block.oe_whitelabel_neutral_footer
- block.block.oe_whitelabel_search_form
Loading

0 comments on commit 1b1df0d

Please sign in to comment.