Skip to content

Commit

Permalink
Merge pull request #1099 from openeuropa/EWPP-2274
Browse files Browse the repository at this point in the history
EWPP-2274: Use external link service.
  • Loading branch information
nagyad authored May 20, 2022
2 parents f71afe5 + a2cbf51 commit ae2ecf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 3 additions & 7 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ declare(strict_types = 1);

use Drupal\block\BlockInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\ContentEntityInterface;
Expand Down Expand Up @@ -1751,6 +1750,8 @@ function _oe_theme_preprocess_site_specific_footer_links(array &$variables): voi
return;
}

$external_link_service = \Drupal::service('oe_theme_helper.external_links');

foreach ($variables['site_specific_footer']['other_links'] as $section => $links) {
if (empty($links['links'])) {
continue;
Expand All @@ -1761,12 +1762,7 @@ function _oe_theme_preprocess_site_specific_footer_links(array &$variables): voi
continue;
}

if ($link['href']->isExternal()) {
$parts = UrlHelper::parse($link['href']->toString());
if (strpos($parts['path'], 'europa.eu')) {
// We consider links with europa.eu domains as internal.
continue;
}
if ($external_link_service->isExternalLink($link['href'])) {
$variables['site_specific_footer']['other_links'][$section]['links'][$index]['external'] = TRUE;
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/src/Functional/CorporateFooterRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ protected function setUp(): void {
$this->container->get('plugin.manager.ui_patterns')->clearCachedDefinitions();
$this->configFactory = $this->container->get('config.factory');
$this->linkManager = $this->container->get('oe_corporate_blocks.footer_link_manager');

// Set the internal domain config to detect external links properly.
$this->config('oe_theme_helper.internal_domains')->set('internal_domain', '/(^|^[^:]+:\/\/|[^\.]+\.)europa\.eu/m')->save();
}

/**
Expand Down

0 comments on commit ae2ecf6

Please sign in to comment.