Skip to content

Commit 4b3beee

Browse files
committed
EWPP-6963: Add the "Subscribe for updates" action button to the site footer.
1 parent 1fbd738 commit 4b3beee

7 files changed

Lines changed: 103 additions & 2 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"openeuropa/code-review-drupal": "^1.0.0-alpha1",
5050
"openeuropa/oe_contact_forms": "^1.24.0",
5151
"openeuropa/oe_content": "4.x-dev",
52-
"openeuropa/oe_corporate_blocks": "5.x-dev",
52+
"openeuropa/oe_corporate_blocks": "dev-EWPP-6963",
5353
"openeuropa/oe_corporate_countries": "2.x-dev",
54-
"openeuropa/oe_corporate_site_info": "1.x-dev",
54+
"openeuropa/oe_corporate_site_info": "dev-EWPP-6963",
5555
"openeuropa/oe_media": "dev-master as 1.37.0",
5656
"openeuropa/oe_multilingual": "dev-master",
5757
"openeuropa/oe_paragraphs": "dev-master",

oe_theme.theme

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ function oe_theme_preprocess_oe_corporate_blocks_ec_footer(array &$variables) {
17081708

17091709
_oe_theme_preprocess_site_specific_footer_links($variables);
17101710
_oe_theme_preprocess_accessibility_link($variables);
1711+
_oe_theme_preprocess_subscribe_link($variables);
17111712
}
17121713

17131714
/**
@@ -1729,6 +1730,7 @@ function oe_theme_preprocess_oe_corporate_blocks_eu_footer(array &$variables) {
17291730

17301731
_oe_theme_preprocess_site_specific_footer_links($variables);
17311732
_oe_theme_preprocess_accessibility_link($variables);
1733+
_oe_theme_preprocess_subscribe_link($variables);
17321734

17331735
// Hide the default Accessibility link inside "Legal" section for
17341736
// standardised ECL branding.
@@ -1844,6 +1846,17 @@ function _oe_theme_preprocess_accessibility_link(array &$variables) {
18441846
$variables['accessibility_link'] = $variables['accessibility_link']->toString();
18451847
}
18461848

1849+
/**
1850+
* Get the Subscribe for updates link.
1851+
*/
1852+
function _oe_theme_preprocess_subscribe_link(array &$variables) {
1853+
if (!isset($variables['subscribe_link']) || !$variables['subscribe_link'] instanceof Url) {
1854+
return;
1855+
}
1856+
1857+
$variables['subscribe_link'] = $variables['subscribe_link']->toString();
1858+
}
1859+
18471860
/**
18481861
* Implements hook_preprocess_HOOK().
18491862
*/

templates/navigation/oe-corporate-blocks-ec-footer--core.html.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
{% else %}
1717
{% set site_owner_description = site_owner ? 'This site is managed by:<br />@name'|t({'@name': site_owner|first}) %}
1818
{% endif %}
19+
{# Build the "Subscribe for updates" action button, if a link is provided. #}
20+
{% set _action_button = [] %}
21+
{% if subscribe_link is not empty %}
22+
{% set _action_button = {
23+
'link': {
24+
'label': 'Subscribe for updates'|t,
25+
'path': subscribe_link,
26+
},
27+
'icon': {
28+
'name': 'envelope-simple',
29+
'family': 'phosphor',
30+
'style': 'inverted',
31+
},
32+
} %}
33+
{% endif %}
1934
{% set section_site_info = {
2035
'logo': {
2136
'picture': {
@@ -28,6 +43,7 @@
2843
'path': path,
2944
},
3045
'description': site_owner ? site_owner_description,
46+
'action_button': _action_button,
3147
} %}
3248

3349
{# Populate the core section. #}

templates/navigation/oe-corporate-blocks-ec-footer--standardised.html.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
{% else %}
1717
{% set site_owner_description = site_owner ? 'This site is managed by:<br />@name'|t({'@name': site_owner|first}) %}
1818
{% endif %}
19+
{# Build the "Subscribe for updates" action button, if a link is provided. #}
20+
{% set _action_button = [] %}
21+
{% if subscribe_link is not empty %}
22+
{% set _action_button = {
23+
'link': {
24+
'label': 'Subscribe for updates'|t,
25+
'path': subscribe_link,
26+
},
27+
'icon': {
28+
'name': 'envelope-simple',
29+
'family': 'phosphor',
30+
'style': 'inverted',
31+
},
32+
} %}
33+
{% endif %}
1934
{% set section_site_info = {
2035
'title': {
2136
'link': {
@@ -30,6 +45,7 @@
3045
}
3146
},
3247
'description': site_owner ? site_owner_description,
48+
'action_button': _action_button,
3349
} %}
3450

3551
{% if site_specific_footer.social_links is not empty %}

templates/navigation/oe-corporate-blocks-eu-footer--core.html.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
{% else %}
1616
{% set site_owner_description = site_owner ? 'This site is managed by:<br />@name'|t({'@name': site_owner|first}) %}
1717
{% endif %}
18+
{# Build the "Subscribe for updates" action button, if a link is provided. #}
19+
{% set _action_button = [] %}
20+
{% if subscribe_link is not empty %}
21+
{% set _action_button = {
22+
'link': {
23+
'label': 'Subscribe for updates'|t,
24+
'path': subscribe_link,
25+
},
26+
'icon': {
27+
'name': 'envelope-simple',
28+
'family': 'phosphor',
29+
'style': 'inverted',
30+
},
31+
} %}
32+
{% endif %}
1833
{% set _row = [
1934
[
2035
{
@@ -27,6 +42,7 @@
2742
'alt': 'European Union flag'|t,
2843
},
2944
'description': site_owner ? site_owner_description,
45+
'action_button': _action_button,
3046
},
3147
],
3248
[

templates/navigation/oe-corporate-blocks-eu-footer--standardised.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
},
9595
'description': site_owner ? site_owner_description,
9696
'links': _top_row_links,
97+
'action_button': _action_button,
9798
'section_class_name': 'ecl-site-footer__section--site-info',
9899
}
99100
],

tests/src/Functional/CorporateFooterRenderTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public function testCorporateFooterRendering(): void {
104104
// Site owner is not set yet, let's make sure we don't have a description.
105105
$assert->elementNotExists('css', 'div.ecl-site-footer__description');
106106

107+
// The subscribe action button is not rendered without a subscribe link.
108+
$assert->elementNotExists('css', 'footer.ecl-site-footer a.ecl-site-footer__action-button');
109+
107110
$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row--specific div.ecl-site-footer__section--core');
108111
foreach (array_values($ec_core_links) as $key => $expected) {
109112
$index = $key + 1;
@@ -120,13 +123,20 @@ public function testCorporateFooterRendering(): void {
120123
$this->assertListLink($actual, $expected);
121124
}
122125

126+
// Set a subscribe link in the corporate site information settings.
127+
$this->configFactory->getEditable('oe_corporate_site_info.settings')->set('subscribe', 'https://example.com/subscribe')->save();
128+
123129
// Update settings, assert footer changed.
124130
$this->updateSiteSettings(['http://publications.europa.eu/resource/authority/corporate-body/ACP-EU_JA'], 'EC Site Name');
125131
$this->drupalGet('<front>');
126132

127133
$actual = $assert->elementExists('css', 'div.ecl-site-footer__description');
128134
$this->assertEquals('This site is managed by:ACP–EU Joint Assembly', $actual->getText());
129135

136+
// Assert the subscribe action button in the site info section.
137+
$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row--specific div.ecl-site-footer__section--site-info');
138+
$this->assertSubscribeActionButton($section, 'secondary-inverted', 'https://example.com/subscribe');
139+
130140
// Test European Commission footer standardised block rendering.
131141
$this->branding = 'standardised';
132142
$this->configFactory->getEditable('oe_theme.settings')->set('branding', $this->branding)->save();
@@ -154,6 +164,9 @@ public function testCorporateFooterRendering(): void {
154164
$actual = $section->find('css', 'div.ecl-site-footer__description');
155165
$this->assertEquals('This site is managed by:ACP–EU Joint Assembly', $actual->getText());
156166

167+
// Assert the subscribe action button in the site info section.
168+
$this->assertSubscribeActionButton($section, 'secondary-inverted', 'https://example.com/subscribe');
169+
157170
$section = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row--common');
158171
// Assert presence of ecl logo in the standardised footer.
159172
$this->assertEclLogoPresence($section);
@@ -240,6 +253,9 @@ public function testCorporateFooterRendering(): void {
240253
// Assert presence of ecl logo in the core footer.
241254
$this->assertEclLogoPresence($section);
242255

256+
// Assert the subscribe action button in the site info section.
257+
$this->assertSubscribeActionButton($section, 'secondary-neutral', 'https://example.com/subscribe');
258+
243259
$column = $assert->elementExists('css', 'footer.ecl-site-footer div.ecl-site-footer__column:nth-child(2)');
244260
$subsection = $assert->elementExists('css', '.ecl-site-footer__section:nth-child(1)', $column);
245261

@@ -332,6 +348,9 @@ public function testCorporateFooterRendering(): void {
332348
$this->assertEquals('Accessibility', $actual->getText());
333349
$this->assertEquals('/build/', $actual->getAttribute('href'));
334350

351+
// Assert the subscribe action button in the site info section.
352+
$this->assertSubscribeActionButton($section, 'secondary-neutral', 'https://example.com/subscribe');
353+
335354
$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)');
336355

337356
$actual = $section->find('css', 'div.ecl-site-footer__description');
@@ -915,6 +934,26 @@ public function testCorporateFooterRendering(): void {
915934
$assert->elementNotExists('css', 'footer.ecl-site-footer div.ecl-site-footer__row--specific .ecl-social-media-follow');
916935
}
917936

937+
/**
938+
* Asserts the "Subscribe for updates" action button in a site info section.
939+
*
940+
* @param \Behat\Mink\Element\NodeElement $section
941+
* The footer site info section.
942+
* @param string $type
943+
* The expected ECL link type, e.g. 'secondary-inverted'.
944+
* @param string $href
945+
* The expected button link.
946+
*/
947+
protected function assertSubscribeActionButton(NodeElement $section, string $type, string $href): void {
948+
$button = $this->assertSession()->elementExists('css', 'a.ecl-site-footer__action-button', $section);
949+
$this->assertEquals('Subscribe for updates', $button->getText());
950+
$this->assertEquals($href, $button->getAttribute('href'));
951+
$this->assertEquals("ecl-link ecl-link--{$type} ecl-link--icon ecl-site-footer__action-button ecl-button--m", $button->getAttribute('class'));
952+
// Assert the default icon: "envelope-simple" from the "phosphor" family
953+
// with the "inverted" style.
954+
$this->assertSession()->elementExists('css', 'span.ecl-icon.ecl-icon-phosphor--envelope-simple.wt-icon--inverted.ecl-link__icon', $button);
955+
}
956+
918957
/**
919958
* Get fixture content.
920959
*

0 commit comments

Comments
 (0)