Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-2875: Add EC logo and remove the title from EC footers. #1224

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,14 @@ function oe_theme_theme_suggestions_oe_corporate_blocks_eu_footer_alter(array &$
* Implements hook_preprocess_HOOK().
*/
function oe_theme_preprocess_oe_corporate_blocks_ec_footer(array &$variables) {
_oe_theme_preprocess_footer_logo($variables);
$language_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
if (!EuropeanUnionLanguages::hasLanguage($language_code)) {
$variables['path'] = 'https://commission.europa.eu/index_en';
}
else {
$variables['path'] = 'https://commission.europa.eu/index_' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']);
}
_oe_theme_preprocess_site_specific_footer_links($variables);
}

Expand All @@ -1731,34 +1739,51 @@ function oe_theme_preprocess_oe_corporate_blocks_eu_footer(array &$variables) {
$variables['logo_description'] = t('Discover more on @link', [
'@link' => new FormattableMarkup('<a href="https://europa.eu/" class="ecl-link ecl-link--standalone">europa.eu</a>', []),
]);
$site_logo_href = 'https://european-union.europa.eu';
// Ensure the site logo falls back to english version if the language is
// not EU language.
_oe_theme_preprocess_footer_logo($variables);
$language_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
if (!EuropeanUnionLanguages::hasLanguage($language_code)) {
if ($language_code === 'nb') {
// Set correct icon for Norwegian language.
$variables['current_language_id'] = 'no';
}
else {
// Check whether ECL provides a logo for the language.
$ecl_logo = DRUPAL_ROOT . '/' . drupal_get_path('theme', 'oe_theme') . '/dist/' . $variables['ecl_component_library'] . '/images/logo/';
$ecl_logo .= $variables['ecl_component_library'] === 'eu' ? 'standard-version/positive/' : 'positive/';
$ecl_logo .= 'logo-' . $variables['ecl_component_library'] . '--' . $language_code . '.svg';
if (!file_exists($ecl_logo)) {
// Provide fallback "en" icon if language logo doesn't exist.
$variables['current_language_id'] = 'en';
}
}
$variables['path'] = 'https://european-union.europa.eu/index_en';
}
else {
$site_logo_href .= '/index_' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']);
$variables['path'] = 'https://european-union.europa.eu/index_' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']);
}
$variables['path'] = $site_logo_href;
$variables['mobile_logo_path'] = str_replace('standard', 'condensed', $variables['desktop_logo_path']);

_oe_theme_preprocess_site_specific_footer_links($variables);
}

/**
* Sets the correct footer desktop logo path.
*/
function _oe_theme_preprocess_footer_logo(array &$variables): void {
// Ensure the site logo falls back to English version if the language is
// not EU language.
$footer_logo_path = $variables['ecl_logo_path'];
$footer_logo_path .= $variables['ecl_component_library'] === 'eu' ? '/standard-version/positive/' : '/negative/';
if (EuropeanUnionLanguages::hasLanguage($variables['current_language_id'])) {
$variables['desktop_logo_path'] = $footer_logo_path . 'logo-' . $variables['ecl_component_library'] . '--' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']) . '.svg';
}
else {
if ($variables['current_language_id'] === 'nb') {
// Set correct icon for Norwegian language.
$variables['desktop_logo_path'] = $footer_logo_path . 'logo-' . $variables['ecl_component_library'] . '--no.svg';
return;
}
// Check whether ECL provides a logo for the language.
$logo_file = DRUPAL_ROOT . '/' . \Drupal::service('extension.list.theme')->getPath('oe_theme') . '/dist/' . $variables['ecl_component_library'] . '/images/logo/';
$logo_file .= $variables['ecl_component_library'] === 'eu' ? 'standard-version/positive/' : 'negative/';
$logo_file .= 'logo-' . $variables['ecl_component_library'] . '--' . $variables['current_language_id'] . '.svg';
if (!file_exists($logo_file)) {
// Provide "en" logo as default, if a logo for the current language
// doesn't exist.
$variables['desktop_logo_path'] = $footer_logo_path . 'logo-' . $variables['ecl_component_library'] . '--en.svg';
return;
}
// If there is a logo file for the current language, we use it.
$variables['desktop_logo_path'] = $footer_logo_path . 'logo-' . $variables['ecl_component_library'] . '--' . $variables['current_language_id'] . '.svg';
}
}

/**
* Helper function to preprocess footer links and set external flag to them.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

{% set _first_column = [
{
'title': {
'link': {
'label': corporate_footer.corporate_site_link.label,
'path': corporate_footer.corporate_site_link.href,
'logo': {
'aria_label': 'Home'|t ~ ' - ' ~ 'European Commission'|t,
'alt': 'European Commission logo'|t,
'title': 'European Commission'|t,
'language': current_language_id,
'path': path,
'src_desktop': desktop_logo_path,
},
},
'description': site_owner ? 'This site is managed by the @name'|t({'@name': site_owner}),
},
] %}
Expand All @@ -36,7 +38,6 @@
},
]
%}

{% block content %}
{% include '@ecl-twig/site-footer' with {
'rows': [[_first_column, _second_column]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@
{% set _bottom_row = [
[
{
'title': {
'link': {
'label': corporate_footer.corporate_site_link.label,
'path': corporate_footer.corporate_site_link.href,
'logo': {
'aria_label': 'Home'|t ~ ' - ' ~ 'European Commission'|t,
'alt': 'European Commission logo'|t,
'title': 'European Commission'|t,
'language': current_language_id,
'path': path,
'src_desktop': desktop_logo_path,
},
},
}
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
'logo': {
'path': path,
'language': current_language_id,
'src_mobile': ecl_logo_path ~ '/condensed-version/positive/logo-eu--' ~ current_language_id|to_internal_language_id ~ '.svg',
'src_desktop': ecl_logo_path ~ '/standard-version/positive/logo-eu--' ~ current_language_id|to_internal_language_id ~ '.svg',
'src_mobile': mobile_logo_path,
'src_desktop': desktop_logo_path,
'title': 'European Union'|t,
'alt': 'European Union flag'|t,
'aria_label': 'Home'|t ~ ' - ' ~ 'European Union'|t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
'logo': {
'path': path,
'language': current_language_id,
'src_mobile': ecl_logo_path ~ '/condensed-version/positive/logo-eu--' ~ current_language_id|to_internal_language_id ~ '.svg',
'src_desktop': ecl_logo_path ~ '/standard-version/positive/logo-eu--' ~ current_language_id|to_internal_language_id ~ '.svg',
'src_mobile': mobile_logo_path,
'src_desktop': desktop_logo_path,
'title': 'European Union'|t,
'alt': 'European Union flag'|t,
'aria_label': 'Home'|t ~ ' - ' ~ 'European Union'|t,
Expand Down
8 changes: 4 additions & 4 deletions tests/features/corporate-blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Corporate blocks feature
Scenario Outline: By default the European Commission footer is displayed.
Given I am an anonymous user
When I am on "<page>"
Then I should see the European Commission footer with link "https://commission.europa.eu/index_en"
Then I should see the "European Commission" footer with link "https://commission.europa.eu/index_en" label "Home - European Commission" image alt "European Commission logo" title "European Commission"

Examples:
| page |
Expand All @@ -27,18 +27,18 @@ Feature: Corporate blocks feature
Scenario Outline: Changing the site's style will display either the European Commission or the European Union footer.
Given I am an anonymous user
When I am on "<page>"
Then I should see the European Commission footer with link "https://commission.europa.eu/index_en"
Then I should see the "European Commission" footer with link "https://commission.europa.eu/index_en" label "Home - European Commission" image alt "European Commission logo" title "European Commission"
And I should not see the "European Union" footer

When the theme is configured to use the "European Union" style
And I reload the page
Then I should not see the "European Commission" footer
But I should see the European Union footer with link "https://european-union.europa.eu/index_en" label "Home - European Union" image alt "European Union flag" title "European Union"
But I should see the "European Union" footer with link "https://european-union.europa.eu/index_en" label "Home - European Union" image alt "European Union flag" title "European Union"

When the theme is configured to use the "European Commission" style
And I reload the page
Then I should not see the "European Union" footer
But I should see the European Commission footer with link "https://commission.europa.eu/index_en"
But I should see the "European Commission" footer with link "https://commission.europa.eu/index_en" label "Home - European Commission" image alt "European Commission logo" title "European Commission"

Examples:
| page |
Expand Down
34 changes: 9 additions & 25 deletions tests/src/Behat/OeThemeTestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,29 +284,13 @@ protected function getDemoPageByTitle(string $title): NodeInterface {
/**
* Assert given corporate footer presence on page.
*
* @Then I should see the European Commission footer with link :link
* @Then I should see the :component_library footer with link :link label :label image alt :img_alt title :img_title
*/
public function assertEuropeanCommissionFooterBlockOnPage(string $link): void {
// Make sure a corporate footer is present on the page.
$this->assertSession()->elementExists('css', 'footer.ecl-site-footer');
// European Commission footer is presented.
Assert::assertEquals('European Commission', $this->getFooterType(), 'European Commission footer is not presented on the page.');

// Assert footer data.
$title_link = $this->getSession()->getPage()->find('css', '.ecl-site-footer__title-link[href="' . $link . '"]');
Assert::assertNotEmpty($title_link, 'European Commission footer link is not found.');
}

/**
* Assert given corporate footer presence on page.
*
* @Then I should see the European Union footer with link :link label :label image alt :img_alt title :img_title
*/
public function assertEuropeanUnionFooterBlockOnPage(string $link, string $label, string $img_alt, string $img_title): void {
public function assertEuropeanFooterBlockOnPage(string $component_library, string $link, string $label, string $img_alt, string $img_title): void {
// Make sure a corporate footer is present on the page.
$this->assertSession()->elementExists('css', 'footer.ecl-site-footer');
// European Union footer is presented.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it is not anymore only the European Union footer.

Assert::assertEquals('European Union', $this->getFooterType(), 'European Union footer is not presented on the page.');
Assert::assertEquals($component_library, $this->getFooterType(), 'European Union footer is not presented on the page.');

// Assert footer data.
$page = $this->getSession()->getPage();
Expand Down Expand Up @@ -371,17 +355,17 @@ public function setCorporateLibrary(string $component_library): void {
* Determines footer type.
*
* The ECL doesn't provide a way to determine type of the footer except as
* to check the existence of the logo.
* 'European Union' has logo, 'European Commission' doesn't.
* to check the attributes of the logo.
*
* @return string
* 'European Union' or 'European Commission'.
*/
protected function getFooterType(): string {
$logo = $this->getSession()
->getPage()
->find('css', 'footer.ecl-site-footer img.ecl-site-footer__logo-image-desktop');
return empty($logo) ? 'European Commission' : 'European Union';
$logo = $this->getSession()->getPage()->find('css', 'footer.ecl-site-footer .ecl-site-footer__logo-link');
if ($logo->getAttribute('aria-label') === 'Home - European Union') {
return 'European Union';
}
return 'European Commission';
}

/**
Expand Down
36 changes: 19 additions & 17 deletions tests/src/Functional/CorporateFooterRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ public function testCorporateFooterRendering(): void {
$this->assertFooterPresence('core', 4);

$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__column:nth-child(1) div.ecl-site-footer__section:nth-child(1)');
// Assert presence of ecl logo in the core footer.
$this->assertEclLogoPresence($section, 'European Commission');

$actual = $section->find('css', 'h2.ecl-site-footer__title a');
$this->assertEquals($data['corporate_site_link']['label'], $actual->getText());
$this->assertEquals($data['corporate_site_link']['href'], $actual->getAttribute('href'));

// Site owner is not set yet, lets make sure we don't have a description.
// Site owner is not set yet, let's make sure we don't have a description.
$assert->elementNotExists('css', 'div.ecl-site-footer__description');

$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__column:nth-child(2) div.ecl-site-footer__section:nth-child(1)');
Expand Down Expand Up @@ -146,9 +144,8 @@ public function testCorporateFooterRendering(): void {
$this->assertEquals('This site is managed by the ACP–EU Joint Assembly', $actual->getText());

$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row:nth-child(2) div.ecl-site-footer__column:nth-child(1) div.ecl-site-footer__section:nth-child(1)');
$actual = $section->find('css', 'h2.ecl-site-footer__title a');
$this->assertEquals($data['corporate_site_link']['label'], $actual->getText());
$this->assertEquals($data['corporate_site_link']['href'], $actual->getAttribute('href'));
// Assert presence of ecl logo in the standardised footer.
$this->assertEclLogoPresence($section, 'European Commission');

$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row:nth-child(2) div.ecl-site-footer__column:nth-child(2) div.ecl-site-footer__section:nth-child(1)');
$items = $data['service_navigation'];
Expand Down Expand Up @@ -199,8 +196,8 @@ public function testCorporateFooterRendering(): void {
$actual = $assert->elementExists('css', 'div.ecl-site-footer__description');
$this->assertEquals('This site is managed by the European Commission, DG XI – Internal Market', $actual->getText());

// Assert presence of ecl logo in footer.
$this->assertEclLogoPresence($section, 'core');
// Assert presence of ecl logo in the core footer.
$this->assertEclLogoPresence($section, 'European Union');

$column = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__column:nth-child(2)');
$subsection = $assert->elementExists('css', '.ecl-site-footer__section:nth-child(1)', $column);
Expand Down Expand Up @@ -286,8 +283,8 @@ public function testCorporateFooterRendering(): void {
$actual = $section->find('css', 'div.ecl-site-footer__description');
$this->assertEquals('Discover more on <a href="https://europa.eu/" class="ecl-link ecl-link--standalone">europa.eu</a>', trim($actual->getHtml()));

// Assert presence of ecl logo in footer.
$this->assertEclLogoPresence($section, 'standardised');
// Assert presence of ecl logo in the standardised footer.
$this->assertEclLogoPresence($section, 'European Union');

$column = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row:nth-child(2) div.ecl-site-footer__column:nth-child(2)');
$subsection = $assert->elementExists('css', '.ecl-site-footer__section:nth-child(1)', $column);
Expand Down Expand Up @@ -934,12 +931,17 @@ protected function assertSocialLink(NodeElement $label, NodeElement $link, array
*
* @param \Behat\Mink\Element\NodeElement $section
* The footer section.
* @param string $branding
* Ecl branding, core/standardised.
* @param string $component_library
* The component library: 'European Commission' or 'European Union'.
*/
protected function assertEclLogoPresence(NodeElement $section, string $branding): void {
$this->assertSession()->elementsCount('css', "a img.ecl-site-footer__logo-image-mobile", 1, $section);
$this->assertSession()->elementsCount('css', "a img.ecl-site-footer__logo-image-desktop", 1, $section);
protected function assertEclLogoPresence(NodeElement $section, string $component_library): void {
if ($component_library === 'European Union') {
$this->assertSession()->elementsCount('css', "a img.ecl-site-footer__logo-image-mobile", 1, $section);
$this->assertSession()->elementsCount('css', "a img.ecl-site-footer__logo-image-desktop", 1, $section);
}
else {
$this->assertSession()->elementsCount('css', "a img.ecl-site-footer__logo-image-desktop", 1, $section);
}
}

/**
Expand Down