From a7aeca3d8a03811de9dc6d3dc3eb381ed0c9966c Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Wed, 11 Oct 2023 10:00:54 +0300 Subject: [PATCH] EWPP-3647: Add Accessibility link to standardised footer blocks. --- composer.json | 4 ++ .../FunctionalJavascript/WysiwygTableTest.php | 2 +- oe_theme.theme | 41 +++++++++++++++++++ runner.yml.dist | 1 + ...e-blocks-ec-footer--standardised.html.twig | 26 +++++++++--- ...e-blocks-eu-footer--standardised.html.twig | 26 +++++++++--- .../Functional/CorporateFooterRenderTest.php | 17 ++++++++ 7 files changed, 106 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 49651bdce..a14fc999e 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "openeuropa/oe_content": "3.x-dev", "openeuropa/oe_corporate_blocks": "^4.14", "openeuropa/oe_corporate_countries": "^2.0.0-alpha8", + "openeuropa/oe_corporate_site_info": "^1.0", "openeuropa/oe_media": "^1.23.1", "openeuropa/oe_multilingual": "^1.13", "openeuropa/oe_paragraphs": "^1.20", @@ -102,6 +103,9 @@ }, "drupal/entity_reference_revisions": { "https://www.drupal.org/project/entity_reference_revisions/issues/2937835": "https://www.drupal.org/files/issues/2021-03-26/entity_reference_revisions-field_formatter_label-2937835-36.patch" + }, + "openeuropa/oe_corporate_site_info": { + "latest-master": "https://github.com/openeuropa/oe_corporate_site_info/compare/1.0.0-alpha7...1.x.diff" } }, "drupal-scaffold": { diff --git a/modules/oe_theme_helper/tests/src/FunctionalJavascript/WysiwygTableTest.php b/modules/oe_theme_helper/tests/src/FunctionalJavascript/WysiwygTableTest.php index 7042a3f43..d79f39943 100644 --- a/modules/oe_theme_helper/tests/src/FunctionalJavascript/WysiwygTableTest.php +++ b/modules/oe_theme_helper/tests/src/FunctionalJavascript/WysiwygTableTest.php @@ -177,7 +177,7 @@ public function testWysiwygTable(): void { $this->click('#cke_edit-oe-teaser-0-value .cke_button__source'); $page->find('css', 'textarea.cke_source')->setValue('test'); $page->fillField('Content owner (value 1)', 'Audit Board of the European Communities (http://publications.europa.eu/resource/authority/corporate-body/ABEC)'); - $page->fillField('Subject (value 1)', 'financing (http://data.europa.eu/uxp/1000)'); + $page->fillField('Subject tags (value 1)', 'financing (http://data.europa.eu/uxp/1000)'); $page->pressButton('Save'); $web_assert->elementExists('css', 'article .ecl table.ecl-table.ecl-table--simple.ecl-table--zebra'); // Assert absence of classes in table related to "Zebra striping" and diff --git a/oe_theme.theme b/oe_theme.theme index 69f4b7b48..001141543 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -28,6 +28,7 @@ use Drupal\media_avportal\Plugin\media\Source\MediaAvPortalSourceInterface; use Drupal\media_avportal\Plugin\media\Source\MediaAvPortalVideoSource; use Drupal\node\NodeInterface; use Drupal\oe_content_person\Entity\PersonJobInterface; +use Drupal\oe_corporate_site_info\SiteInformation; use Drupal\oe_media_iframe\Plugin\media\Source\Iframe; use Drupal\oe_theme\DocumentMediaValueExtractor; use Drupal\oe_theme\ValueObject\DateValueObject; @@ -1784,6 +1785,7 @@ function oe_theme_preprocess_oe_corporate_blocks_ec_footer(array &$variables) { $variables['path'] = 'https://commission.europa.eu/index_' . EuropeanUnionLanguages::getInternalLanguageCode($variables['current_language_id']); } _oe_theme_preprocess_site_specific_footer_links($variables); + _oe_theme_preprocess_accessibility_link($variables); } /** @@ -1804,6 +1806,7 @@ function oe_theme_preprocess_oe_corporate_blocks_eu_footer(array &$variables) { $variables['mobile_logo_path'] = str_replace('standard', 'condensed', $variables['desktop_logo_path']); _oe_theme_preprocess_site_specific_footer_links($variables); + _oe_theme_preprocess_accessibility_link($variables); } /** @@ -1868,6 +1871,44 @@ function _oe_theme_preprocess_site_specific_footer_links(array &$variables): voi } } +/** + * Get the Accessibility statement link. + */ +function _oe_theme_preprocess_accessibility_link(array &$variables) { + if (!\Drupal::service('module_handler')->moduleExists('oe_corporate_site_info')) { + return; + } + $cacheability = CacheableMetadata::createFromRenderArray($variables); + $configuration = \Drupal::configFactory()->get(SiteInformation::CONFIG_NAME); + $cacheability->addCacheableDependency($configuration); + /** @var \Drupal\oe_corporate_site_info\SiteInformationInterface $site_information */ + $site_information = \Drupal::service('oe_corporate_site_info.site_information'); + if (!$site_information->hasAccessibilityLink()) { + $cacheability->applyTo($variables); + return; + } + $uri = $site_information->getAccessibilityLink(); + $uri_parts = parse_url($uri); + if ($uri_parts['scheme'] === 'entity') { + [$entity_type_id, $entity_id] = explode('/', $uri_parts['path'], 2); + $entity = \Drupal::entityTypeManager()->getStorage($entity_type_id)->load($entity_id); + if ($entity instanceof NodeInterface) { + $cacheability->addCacheableDependency($entity); + $access = $entity->access('view', \Drupal::currentUser(), TRUE); + $cacheability->addCacheableDependency($access); + if (!$access->isAllowed()) { + $cacheability->applyTo($variables); + // Do not show the button if access to the node is forbidden. + return; + } + } + } + $url = Url::fromUri($uri)->toString(); + + $variables['accessibility_link'] = $url; + $cacheability->applyTo($variables); +} + /** * Implements hook_preprocess_HOOK(). */ diff --git a/runner.yml.dist b/runner.yml.dist index 6bad5d18f..3b031ec0b 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -20,6 +20,7 @@ drupal: - "./vendor/bin/drush en oe_multilingual -y" - "./vendor/bin/drush en oe_search -y" - "./vendor/bin/drush en oe_corporate_blocks -y" + - "./vendor/bin/drush en oe_corporate_site_info -y" - "./vendor/bin/drush en oe_theme_content_page -y" - "./vendor/bin/drush en oe_theme_content_news -y" - "./vendor/bin/drush en oe_theme_content_policy -y" diff --git a/templates/navigation/oe-corporate-blocks-ec-footer--standardised.html.twig b/templates/navigation/oe-corporate-blocks-ec-footer--standardised.html.twig index f0e5d6a7e..4a71f3e20 100644 --- a/templates/navigation/oe-corporate-blocks-ec-footer--standardised.html.twig +++ b/templates/navigation/oe-corporate-blocks-ec-footer--standardised.html.twig @@ -58,16 +58,32 @@ {% endif %} {# Populate the top row with the site identity and the custom links. #} +{% set _top_row_links = [] %} +{% if accessibility_link is not empty %} + {% set _top_row_links = { + links: { + link: { + label: 'Accessibility'|t, + path: accessibility_link, + external: accessibility_link|is_external_url, + icon_path: ecl_icon_path, + } + } + } %} +{% endif %} + {% set _top_row = [ [ { 'title': { - 'link': { - 'label': site_specific_footer.site_identity, - 'path': url(''), - } - }, + 'link': { + 'label': site_specific_footer.site_identity, + 'path': url(''), + } + }, 'description': site_owner ? 'This site is managed by: @name'|t({'@name': site_owner}), + 'links': _top_row_links, + 'section_class_name': 'ecl-site-footer__section--site-info', } ], _top_left_column, diff --git a/templates/navigation/oe-corporate-blocks-eu-footer--standardised.html.twig b/templates/navigation/oe-corporate-blocks-eu-footer--standardised.html.twig index cbfe76f83..5ac1277d5 100644 --- a/templates/navigation/oe-corporate-blocks-eu-footer--standardised.html.twig +++ b/templates/navigation/oe-corporate-blocks-eu-footer--standardised.html.twig @@ -15,16 +15,32 @@ {% block content %} {# Populate the top row with the site identity and the custom links. #} + {% set _top_row_links = [] %} + {% if accessibility_link is not empty %} + {% set _top_row_links = { + links: { + link: { + label: 'Accessibility'|t, + path: accessibility_link, + external: accessibility_link|is_external_url, + icon_path: ecl_icon_path, + } + } + } %} + {% endif %} + {% set _top_row = [ [ { 'title': { - 'link': { - 'label': site_specific_footer.site_identity, - 'path': url(''), - } - }, + 'link': { + 'label': site_specific_footer.site_identity, + 'path': url(''), + } + }, 'description': site_owner ? 'This site is managed by: @name'|t({'@name': site_owner}), + 'links': _top_row_links, + 'section_class_name': 'ecl-site-footer__section--site-info', } ], _top_left_column, diff --git a/tests/src/Functional/CorporateFooterRenderTest.php b/tests/src/Functional/CorporateFooterRenderTest.php index 69d5f7d23..3e91999da 100644 --- a/tests/src/Functional/CorporateFooterRenderTest.php +++ b/tests/src/Functional/CorporateFooterRenderTest.php @@ -37,6 +37,7 @@ class CorporateFooterRenderTest extends BrowserTestBase { 'block', 'oe_theme_helper', 'oe_corporate_blocks', + 'oe_corporate_site_info', ]; /** @@ -72,6 +73,7 @@ protected function setUp(): void { * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testCorporateFooterRendering(): void { + $user = $this->createUser([], '', TRUE); // First test European Commission footer core block rendering. $data = $this->getFixtureContent('ec_footer.yml'); $this->overrideCorporateBlocksFooter('ec', $data); @@ -127,6 +129,13 @@ public function testCorporateFooterRendering(): void { $this->configFactory->getEditable('oe_theme.settings')->set('branding', 'standardised')->save(); $data = $this->getFixtureContent('ec_footer.yml'); $this->overrideCorporateBlocksFooter('ec', $data); + // Set an accessibility link. + $this->drupalLogin($user); + $this->drupalGet('/admin/config/system/site-information'); + $this->getSession()->getPage()->fillField('Accessibility statement', ''); + $this->getSession()->getPage()->fillField('content_owners[0][target]', 'Audit Board of the European Communities'); + $this->getSession()->getPage()->pressButton('Save configuration'); + $this->drupalLogout(); $this->drupalGet(''); $assert = $this->assertSession(); @@ -142,6 +151,9 @@ public function testCorporateFooterRendering(): void { $actual = $section->find('css', 'div.ecl-site-footer__description'); $this->assertEquals('This site is managed by: ACP–EU Joint Assembly', $actual->getText()); + $actual = $section->find('css', '.ecl-site-footer__section--site-info a.ecl-link.ecl-link--standalone.ecl-site-footer__link'); + $this->assertEquals('Accessibility', $actual->getText()); + $this->assertEquals('/build/', $actual->getAttribute('href')); $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)'); // Assert presence of ecl logo in the standardised footer. @@ -195,6 +207,8 @@ public function testCorporateFooterRendering(): void { $actual = $assert->elementExists('css', 'div.ecl-site-footer__description'); $this->assertEquals('This site is managed by: DG XI – Internal Market', $actual->getText()); + // Accessibility link should not be displayed on core. + $this->assertCount(0, $section->findAll('css', 'a.ecl-link.ecl-link--standalone.ecl-site-footer__link')); // Assert presence of ecl logo in the core footer. $this->assertEclLogoPresence($section, 'European Union'); @@ -277,6 +291,9 @@ public function testCorporateFooterRendering(): void { $actual = $assert->elementExists('css', 'div.ecl-site-footer__description'); $this->assertEquals('This site is managed by: Directorate-General for Budget', $actual->getText()); + $actual = $section->find('css', '.ecl-site-footer__section--site-info a.ecl-link.ecl-link--standalone.ecl-site-footer__link'); + $this->assertEquals('Accessibility', $actual->getText()); + $this->assertEquals('/build/', $actual->getAttribute('href')); $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)');