Skip to content

Commit

Permalink
Merge pull request #36 from openeuropa/OEL-579-all
Browse files Browse the repository at this point in the history
OEL-579 - Whitelabel - Medley branch with BCL 0.9.0 upgradel
  • Loading branch information
drishu authored Oct 28, 2021
2 parents 6480331 + 9644579 commit 8a08f4c
Show file tree
Hide file tree
Showing 76 changed files with 15,233 additions and 247 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"drupal/core": "^8.9 || ^9.1",
"drupal/ui_patterns": "^1.0",
"drupal/ui_patterns_settings": "^1.0",
"openeuropa/oe_bootstrap_theme": "0.181020211745"
"openeuropa/oe_bootstrap_theme": "0.281020211203"
},
"require-dev": {
"composer/installers": "^1.11",
Expand All @@ -37,7 +37,7 @@
"post-update-cmd": "./vendor/bin/run drupal:site-setup"
},
"repositories": {
"0": {
"drupal":{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
Expand Down
2 changes: 2 additions & 0 deletions modules/oe_whitelabel_helper/oe_whitelabel_helper.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ type: module
description: OpenEuropa Whitelabel Theme helpers and tools.
package: OpenEuropa Whitelabel Theme
core_version_requirement: ^8.9 || ^9.1

'interface translation project': oe_whitelabel_helper
15 changes: 15 additions & 0 deletions modules/oe_whitelabel_helper/oe_whitelabel_helper.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @file
* The OE Whitelabel Helper module.
*/

declare(strict_types = 1);

/**
* Implements hook_locale_translation_projects_alter().
*/
function oe_whitelabel_helper_locale_translation_projects_alter(&$projects) {
$projects['oe_whitelabel_helper']['info']['interface translation server pattern'] = drupal_get_path('module', 'oe_whitelabel_helper') . '/translations/%project-%language.po';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Language\LanguageManagerInterface;

Expand Down Expand Up @@ -80,15 +81,37 @@ public function build(): array {
$logo_path = drupal_get_path('module', 'oe_whitelabel_helper') . '/images/logos/ec';
$title = $this->configFactory->get('system.site')->get('name');

$build = [
$image = [
'#theme' => 'image',
'#uri' => $logo_path . '/logo-ec--' . $language . '.svg',
'#width' => '240px',
'#height' => '60px',
'#alt' => $title,
'#title' => $title,
];

$mobile_url = file_create_url($logo_path . '/mobile/logo-ec--' . $language . '.svg');

$inline_template = [
'#type' => 'inline_template',
'#template' => '<picture><source media="(max-width: 25em)" srcset="{{ mobile }}">{{ image }}</picture>',
'#context' => [
'image' => $image,
'mobile' => file_url_transform_relative($mobile_url),
],
];

$build = [
'#type' => 'link',
'#url' => Url::fromUri('https://ec.europa.eu/info/index_' . $language, [
'attributes' => [
'class' => [
'navbar-brand',
],
'target' => '_blank',
],
]),
'#title' => $inline_template,
];

$cache->applyTo($build);

return $build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Language\LanguageManagerInterface;

Expand Down Expand Up @@ -83,21 +84,34 @@ public function build(): array {
$image = [
'#theme' => 'image',
'#uri' => $logo_path . '/logo-eu--' . $language . '.svg',
'#width' => '240px',
'#height' => '60px',
'#alt' => $title,
'#title' => $title,
];

$mobile_url = file_create_url($logo_path . '/mobile/logo-eu--' . $language . '.svg');
$build = [

$inline_template = [
'#type' => 'inline_template',
'#template' => '<picture><source media="(max-width: 25em)" srcset="{{ mobile }}">{{ image }}</picture>',
'#template' => '<picture><source media="(max-width: 992px)" srcset="{{ mobile }}">{{ image }}</picture>',
'#context' => [
'image' => $image,
'mobile' => file_url_transform_relative($mobile_url),
],
];

$build = [
'#type' => 'link',
'#url' => Url::fromUri('https://europa.eu/european-union/index_' . $language, [
'attributes' => [
'class' => [
'navbar-brand',
],
'target' => '_blank',
],
]),
'#title' => $inline_template,
];

$cache->applyTo($build);

return $build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ public function bclFooterLinks(array $context, array $links): array {
'label' => $link['label'],
'path' => $link['href'],
'icon_position' => 'after',
'attributes' => [
'class' => [
'text-decoration-none',
'd-block',
'mb-1',
],
],
];

if (!empty($link['external']) && $link['external'] === TRUE) {
$altered_link['icon'] = [
'path' => $context['bcl_icon_path'],
'name' => 'external',
'name' => 'box-arrow-up-right',
'size' => 'xs',
];
}
Expand All @@ -71,6 +78,7 @@ public function bclFooterLinks(array $context, array $links): array {
$altered_link['icon'] = [
'path' => $context['bcl_icon_path'],
'name' => $link['social_network'],
'size' => 'xs',
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public function testLogoBlockRendering(string $lang): void {
$render = $this->container->get('renderer')->renderRoot($build);
$crawler = new Crawler($render->__toString());

$actual = $crawler->filter('#block-eclogoblock');
$this->assertCount(1, $actual);
$logo = $actual->filter('img');
$logo = $crawler->filter('img');
$this->assertCount(1, $logo);
$expected = "/themes/custom/oe_whitelabel/modules/oe_whitelabel_helper/images/logos/ec/logo-ec--{$lang}.svg";
$this->assertSame($expected, $logo->attr('src'));
Expand All @@ -115,15 +113,13 @@ public function testLogoBlockRendering(string $lang): void {
$render = $this->container->get('renderer')->renderRoot($build);
$crawler = new Crawler($render->__toString());

$actual = $crawler->filter('#block-eulogoblock');
$this->assertCount(1, $actual);
$logo = $actual->filter('img');
$logo = $crawler->filter('img');
$this->assertCount(1, $logo);
$expected = "/themes/custom/oe_whitelabel/modules/oe_whitelabel_helper/images/logos/eu/logo-eu--{$lang}.svg";
$this->assertSame($expected, $logo->attr('src'));
$picture = $actual->filter('picture');
$picture = $crawler->filter('picture');
$this->assertCount(1, $picture);
$source = $actual->filter('source');
$source = $crawler->filter('source');
$expected = "/themes/custom/oe_whitelabel/modules/oe_whitelabel_helper/images/logos/eu/mobile/logo-eu--{$lang}.svg";
$this->assertSame($expected, $source->attr('srcset'));
}
Expand Down
Loading

0 comments on commit 8a08f4c

Please sign in to comment.