-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1130 from openeuropa/update-EPIC-EWPP-2106-Carousel
EWPP-2106: Update Carousel epic branch.
- Loading branch information
Showing
90 changed files
with
1,016 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
modules/oe_theme_helper/config/install/oe_theme_helper.internal_domains.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
internal_domain: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_theme_helper; | ||
|
||
use Drupal\Component\Utility\UrlHelper; | ||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use Drupal\Core\Url; | ||
|
||
/** | ||
* Verifies if a URL is considered external or internal. | ||
*/ | ||
class ExternalLinks implements ExternalLinksInterface { | ||
|
||
/** | ||
* The internal domain regex. | ||
* | ||
* @var string | ||
*/ | ||
protected string $internalDomainExpression; | ||
|
||
/** | ||
* Constructs an ExternalLinks object. | ||
* | ||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | ||
* The configuration factory. | ||
*/ | ||
public function __construct(ConfigFactoryInterface $config_factory) { | ||
$this->internalDomainExpression = $config_factory->get('oe_theme_helper.internal_domains')->get('internal_domain') ?? ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isExternalLink($url = NULL): bool { | ||
// If no value is provided or the value si not a proper link, we'll | ||
// return FALSE as it can't be evaluated. | ||
if (!$url) { | ||
return FALSE; | ||
} | ||
if ($url instanceof Url) { | ||
$external = $url->isExternal(); | ||
$path = UrlHelper::parse($url->toString())['path']; | ||
} | ||
else { | ||
$external = UrlHelper::isExternal($url); | ||
$path = UrlHelper::parse($url)['path']; | ||
} | ||
if (!$external) { | ||
return $external; | ||
} | ||
|
||
// If it's an external link, make sure its domain is not internal. | ||
if (!$this->internalDomainExpression) { | ||
return $external; | ||
} | ||
return !preg_match_all($this->internalDomainExpression, $path); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_theme_helper; | ||
|
||
use Drupal\Core\Url; | ||
|
||
/** | ||
* Interface for the external links service. | ||
*/ | ||
interface ExternalLinksInterface { | ||
|
||
/** | ||
* Checks whether a link is considered external. | ||
* | ||
* @param \Drupal\Core\Url|string $url | ||
* The url object. | ||
* | ||
* @return bool | ||
* TRUE if the link is external, FALSE otherwise. | ||
*/ | ||
public function isExternalLink(Url $url): bool; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/oe_theme_helper/tests/src/Kernel/ExternalLinksTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\Tests\oe_theme_helper\Kernel; | ||
|
||
use Drupal\Core\Url; | ||
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase; | ||
|
||
/** | ||
* Provides test coverage for the ExternalLinks service. | ||
* | ||
* @group batch1 | ||
*/ | ||
class ExternalLinksTest extends AbstractKernelTestBase { | ||
|
||
/** | ||
* Covers isExternalLink method. | ||
*/ | ||
public function testIsExternalLink(): void { | ||
$external_links = $this->container->get('oe_theme_helper.external_links'); | ||
// Assert internal URL. | ||
$this->assertFalse($external_links->isExternalLink(Url::fromUserInput('/user'))); | ||
// Assert external string path. | ||
$this->assertTrue($external_links->isExternalLink('https://example.com')); | ||
// Assert external string path under EU domain. | ||
$this->assertFalse($external_links->isExternalLink('https://example.europa.eu')); | ||
$this->assertFalse($external_links->isExternalLink('www.ec.europa.eu/info')); | ||
// Assert null and empty value. | ||
$this->assertFalse($external_links->isExternalLink()); | ||
$this->assertFalse($external_links->isExternalLink('')); | ||
// Assert incorrect paths. | ||
$this->assertFalse($external_links->isExternalLink('www. incorrect . com')); | ||
$this->assertFalse($external_links->isExternalLink('www. ec . europa . eu')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.