-
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 #7 from openeuropa/OEL-452
OEL-452: Multilingual
- Loading branch information
Showing
9 changed files
with
425 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# OpenEuropa Whitelabel Helper | ||
|
||
This module offers some additional functionality that might come in useful when | ||
theming an OpenEuropa website. | ||
|
||
Here is an overview of the features it offers: | ||
|
||
### Corporate Logo Blocks | ||
|
||
Two blocks, one for EC one for EU displaying the European Commission and European Union logos linked. | ||
|
||
### Enables OE Authentication | ||
|
||
Enables the [OpenEuropa Authentication](https://github.com/openeuropa/oe_authentication) module so the themed login block can be picked up by Drupal. | ||
|
||
### Enables OE Multilingual | ||
|
||
Enables the [OpenEuropa Multilingual](https://github.com/openeuropa/oe_multilingual) module. | ||
The language switcher block is themed out of the box. | ||
|
||
## Requirements | ||
|
||
To be able to enable this module you will have to provide the dependent modules in your projects composer.json | ||
|
||
``` | ||
composer require openeuropa/oe_authentication | ||
composer require openeuropa/oe_multilingual | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Functions to support theming. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Implements hook__preprocess_links__language_block(). | ||
*/ | ||
function oe_whitelabel_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
42 changes: 42 additions & 0 deletions
42
templates/overrides/navigation/links--language-block.html.twig
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,42 @@ | ||
{% spaceless %} | ||
|
||
{# Parameters: | ||
- language | ||
- link | ||
- label | ||
- href | ||
- target | ||
- modal | ||
#} | ||
|
||
{% set _language = { | ||
link: { | ||
label: language.link.name|default(''), | ||
href: language.link.href|default('#'), | ||
target: language.link.target|default(language.modal.id|default('')), | ||
}, | ||
modal: language.modal, | ||
} %} | ||
{% set extra_attributes = create_attribute() %} | ||
{% set extra_attributes = extra_attributes.setAttribute('data-bs-toggle', 'modal') %} | ||
{% set extra_attributes = extra_attributes.setAttribute('data-bs-target', '#' ~ _language.link.target) %} | ||
{% set extra_attributes = extra_attributes.addClass('nav-link') %} | ||
|
||
<ul class="nav"> | ||
<li class="nav-item"> | ||
{{ pattern('link', { | ||
label: _language.link.label, | ||
path: _language.link.href, | ||
icon: { | ||
name: 'chat-left-dots-fill', | ||
size: 's' | ||
}, | ||
icon_position: 'before', | ||
attributes: extra_attributes | ||
}) }} | ||
</li> | ||
</ul> | ||
|
||
{% include '@oe_whitelabel/patterns/modal/modal-language.html.twig' with _language.modal only %} | ||
|
||
{% endspaceless %} |
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,82 @@ | ||
{% spaceless %} | ||
|
||
{# Parameters: | ||
- modal | ||
- id | ||
- size | ||
- header | ||
- title | ||
- label | ||
- body | ||
- links | ||
- footer | ||
- label | ||
#} | ||
|
||
{% if header %} | ||
{% set _header %} | ||
<h5 class="modal-title" id="languageeModalLabel">{{ header.title|default('Select your language'|t) }}</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ header.label|default('Close'|t) }}"></button> | ||
{% endset %} | ||
{% endif %} | ||
|
||
{% if eu_links or non_eu_links %} | ||
{% set _body %} | ||
<div class="container"> | ||
<div class="row"> | ||
{% set _number_items = (eu_links|length / 2) %} | ||
{% for link in eu_links|batch(_number_items) %} | ||
{% if loop.index % 2 == 0 %} | ||
<div class="col col-lg-4 offset-lg-2"> | ||
{% else %} | ||
<div class="col col-lg-4"> | ||
{% endif %} | ||
<div class="oe-language__list"> | ||
{% for id, data in link %} | ||
<a id="{{ data.id }}" href="{{ data.href|default('#') }}" class="oe-language__item">{{ data.name }}</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% if non_eu_links %} | ||
<div class="row"> | ||
{% set _number_items = (non_eu_links|length / 2) %} | ||
{% for link in non_eu_links|batch(_number_items) %} | ||
{% if loop.index % 2 == 0 %} | ||
<div class="col col-lg-4 offset-lg-2"> | ||
{% else %} | ||
<div class="col col-lg-4"> | ||
{% endif %} | ||
<div class="oe-language__list"> | ||
{% for id, data in link %} | ||
<a id="{{ data.id }}" href="{{ data.href|default('#') }}" class="oe-language__item">{{ data.name }}</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% endset %} | ||
{% endif %} | ||
|
||
{% if footer %} | ||
{% set _footer %} | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ header.label|default('Close'|t) }}</button> | ||
{% endset %} | ||
{% endif %} | ||
|
||
{% set _data = { | ||
id: id, | ||
size: size, | ||
header: _header, | ||
body: _body, | ||
footer: _footer, | ||
} %} | ||
|
||
<div class="oe-language"> | ||
{% include '@oe-bcl/bcl-modal/modal.html.twig' with _data only %} | ||
</div> | ||
|
||
{% endspaceless %} |
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.