diff --git a/modules/oe_webtools_cookie_consent/README.md b/modules/oe_webtools_cookie_consent/README.md index 21d32934..c3eb7d3c 100644 --- a/modules/oe_webtools_cookie_consent/README.md +++ b/modules/oe_webtools_cookie_consent/README.md @@ -34,6 +34,16 @@ $config['oe_webtools_cookie_consent.settings']['video_popup'] = true; ``` +### Iframe URL override + +To override the default iframe URL, you can add the: + +``` +$settings['webtools_cookie_consent_embed_cookie_url'] = 'https://webtools.europa.eu/crs/iframe/'; +``` +If you wish to use the default, you don't need to do anything, it works out of +the box. + ## Upgrade to CCK v2 Cookie Consent Kit v2 requires the smartloader library which is declared in oe_webtools module. This new dependency will be applied by running the post_update_00002 for existing installations. diff --git a/modules/oe_webtools_cookie_consent/oe_webtools_cookie_consent.module b/modules/oe_webtools_cookie_consent/oe_webtools_cookie_consent.module index 61b6839c..6e085fcf 100644 --- a/modules/oe_webtools_cookie_consent/oe_webtools_cookie_consent.module +++ b/modules/oe_webtools_cookie_consent/oe_webtools_cookie_consent.module @@ -9,13 +9,14 @@ declare(strict_types=1); use Drupal\Component\Serialization\Json; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\media\IFrameMarkup; use Drupal\oe_webtools_cookie_consent\Event\ConfigBannerPopupEvent; use Drupal\oe_webtools_cookie_consent\Event\ConfigVideoPopupEvent; use Drupal\oe_webtools_cookie_consent\Form\WebtoolsCookieConsentSettingsForm; -const OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL = 'https://webtools.europa.eu/crs/iframe/'; +define("OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL", Settings::get('webtools_cookie_consent_embed_cookie_url') ?? 'https://webtools.europa.eu/crs/iframe/'); /** * Implements hook_page_bottom(). diff --git a/modules/oe_webtools_cookie_consent/tests/src/Kernel/IframeFilterPluginKernelTest.php b/modules/oe_webtools_cookie_consent/tests/src/Kernel/IframeFilterPluginKernelTest.php index 83a22602..fcd7ff18 100644 --- a/modules/oe_webtools_cookie_consent/tests/src/Kernel/IframeFilterPluginKernelTest.php +++ b/modules/oe_webtools_cookie_consent/tests/src/Kernel/IframeFilterPluginKernelTest.php @@ -23,7 +23,6 @@ class IframeFilterPluginKernelTest extends KernelTestBase { 'system', 'filter', 'language', - 'oe_webtools_cookie_consent', ]; /** @@ -40,6 +39,9 @@ protected function setUp(): void { * Tests the iframe with cookie consent kit filter. */ public function testIframeFilter() { + // Enable the module inside test method to allow other tests to initialize + // with specific settings. + $this->enableModules(['oe_webtools_cookie_consent']); $manager = $this->container->get('plugin.manager.filter'); $filters = new FilterPluginCollection($manager, []); $cck_filter = $filters->get('filter_iframe_cck'); @@ -56,4 +58,21 @@ public function testIframeFilter() { $this->assertEquals($expected, $cck_filter->process($input, LanguageInterface::LANGCODE_NOT_SPECIFIED)->getProcessedText()); } + /** + * Tests the iframe URL override through settings. + */ + public function testOverrideCookieConsentExternalUrls(): void { + // Initialize settings for overriding default iframe URL. + $this->setSetting('webtools_cookie_consent_embed_cookie_url', 'https://webtools.europa.eu/crs/iframe/'); + $this->enableModules(['oe_webtools_cookie_consent']); + $manager = \Drupal::service('plugin.manager.filter'); + $filters = new FilterPluginCollection($manager, []); + $cck_filter = $filters->get('filter_iframe_cck'); + $input = '

'; + + // Assert application of iframe URL through settings. + $expected = '

'; + $this->assertEquals($expected, $cck_filter->process($input, LanguageInterface::LANGCODE_NOT_SPECIFIED)->getProcessedText()); + } + }