Skip to content

Commit

Permalink
EWPP-3647: Add Accessibility link to standardised footer blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Oct 26, 2023
1 parent 61c9762 commit de4393e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 10 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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...EWPP-3647.diff"
}
},
"drupal-scaffold": {
Expand Down
41 changes: 41 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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;
Expand Down Expand Up @@ -1783,6 +1784,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);
}

/**
Expand All @@ -1803,6 +1805,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);
}

/**
Expand Down Expand Up @@ -1867,6 +1870,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().
*/
Expand Down
1 change: 1 addition & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,31 @@
{% 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('<front>'),
}
},
'link': {
'label': site_specific_footer.site_identity,
'path': url('<front>'),
}
},
'description': site_owner ? 'This site is managed by: @name'|t({'@name': site_owner}),
'links': _top_row_links,
}
],
_top_left_column,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,31 @@

{% 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('<front>'),
}
},
'link': {
'label': site_specific_footer.site_identity,
'path': url('<front>'),
}
},
'description': site_owner ? 'This site is managed by: @name'|t({'@name': site_owner}),
'links': _top_row_links,
}
],
_top_left_column,
Expand Down
17 changes: 17 additions & 0 deletions tests/src/Functional/CorporateFooterRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CorporateFooterRenderTest extends BrowserTestBase {
'block',
'oe_theme_helper',
'oe_corporate_blocks',
'oe_corporate_site_info',
];

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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', '<front>');
$this->getSession()->getPage()->fillField('content_owners[0][target]', 'Audit Board of the European Communities');
$this->getSession()->getPage()->pressButton('Save configuration');
$this->drupalLogout();

$this->drupalGet('<front>');
$assert = $this->assertSession();
Expand All @@ -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', '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.
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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', '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)');

Expand Down

0 comments on commit de4393e

Please sign in to comment.