Skip to content

Commit

Permalink
EWPP-4267: Add override for webtools iframe URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle committed Oct 16, 2024
1 parent 1c8cad6 commit 4d580b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions modules/oe_webtools_cookie_consent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class IframeFilterPluginKernelTest extends KernelTestBase {
'system',
'filter',
'language',
'oe_webtools_cookie_consent',
];

/**
Expand All @@ -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');
Expand All @@ -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 = '<p><iframe src="https://example.com?q=a+b&p=1" style="width: 400px; height: 200px;"></iframe></p>';

// Assert application of iframe URL through settings.
$expected = '<p><iframe src="https://webtools.europa.eu/crs/iframe/?oriurl=https%3A//example.com%3Fq%3Da%2Bb%26p%3D1&amp;lang=en" style="width: 400px; height: 200px;"></iframe></p>';
$this->assertEquals($expected, $cck_filter->process($input, LanguageInterface::LANGCODE_NOT_SPECIFIED)->getProcessedText());
}

}

0 comments on commit 4d580b0

Please sign in to comment.