Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit ed44c372 authored by escuriola's avatar escuriola
Browse files

OEL-1307: Language modal BCL 0.20.0 update.

parent df6d83cd
No related branches found
No related tags found
2 merge requests!103Merge 1.x into EPIC-OEL-1255-migrate-paragraphs, and up oebt version.,!91OEL-1307: Update oe_whitelabel to BCL 0.20.0
......@@ -11,6 +11,62 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\oe_whitelabel_helper\EuropeanUnionLanguages;
/**
* 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 = [
'path' => $href,
'name' => $label,
'id' => 'link_' . $language_code,
'label' => $label,
'lang' => $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']['language_list'] = [
'overlay' => TRUE,
'variant' => $variables['bcl_component_library'],
'title' => t('Select your language'),
'items' => $eu_links,
'non_eu_items' => $non_eu_links,
'icon_path' => $variables['bcl_icon_path'],
'id' => 'languageModal',
'size' => 'fullscreen',
];
}
/**
* Implements hook_form_FORM_ID_alter() for facets_forms.
*/
......
{% 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">
<div class="col col-lg-8 offset-lg-2">
<h5 class="bcl-language__title">{{ 'EU official languages'|t }}</h5>
</div>
</div>
<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="bcl-language__list">
{% for id, data in link %}
<a id="{{ data.id }}" href="{{ data.href|default('#') }}" class="bcl-language__item">{{ data.name }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% if non_eu_links %}
<div class="row">
<div class="col col-lg-8 offset-lg-2">
<h5 class="bcl-language__title">{{ 'Non EU languages'|t }}</h5>
</div>
</div>
<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="bcl-language__list">
{% for id, data in link %}
<a id="{{ data.id }}" href="{{ data.href|default('#') }}" class="bcl-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="bcl-language">
{% include '@oe-bcl/bcl-modal/modal.html.twig' with _data only %}
</div>
{% endspaceless %}
{% include '@oe-bcl/bcl-language-list/language-list.html.twig' with language_list only %}
......@@ -87,13 +87,11 @@ class MultilingualBlockTest extends KernelTestBase {
$this->assertCount(1, $block);
$link = $crawler->filter('div.language-switcher > a');
$this->assertSame('English', trim($link->text()));
$this->assertSame('http://localhost/en/%3Cnone%3E', $link->attr('href'));
$title = $crawler->filter('h5#languageeModalLabel');
$this->assertSame('#', $link->attr('href'));
$title = $crawler->filter('div#languageModal h5');
$this->assertSame('Select your language', $title->text());
$button_header = $crawler->filter('button.btn-close');
$this->assertSame('Close', $button_header->attr('aria-label'));
$button_close = $crawler->filter('button.btn.btn-secondary');
$this->assertSame('Close', $button_close->text());
$this->assertSame('modal', $button_header->attr('data-bs-dismiss'));
$link_language = $crawler->filter('a#link_bg');
$this->assertSame('http://localhost/bg/%3Cnone%3E', $link_language->attr('href'));
$this->assertSame('български', $link_language->text());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment