Skip to content

Commit 918d103

Browse files
committed
Reformat code, DEV-1111
Signed-off-by: Iman Aboheydary <[email protected]>
1 parent ce24408 commit 918d103

File tree

5 files changed

+50
-41
lines changed

5 files changed

+50
-41
lines changed

Model/ExternalVideoReplacer.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66

77
class ExternalVideoReplacer
88
{
9-
/**
10-
* Replace iframe sources with cookie consent attributes for YouTube, Vimeo, and Google Maps
11-
*
12-
* @param string $content
13-
* @return string
14-
*/
159
public function replaceIframeSources(string $content): string
1610
{
17-
// Pattern to match iframe sources for various services
1811
$iframePatterns = [
1912
// YouTube patterns
2013
'/<iframe([^>]*)\s+src=["\'](https?:\/\/(?:www\.)?(?:youtube\.com|youtube-nocookie\.com)\/embed\/[^"\']+)["\']([^>]*)>/i',
@@ -28,15 +21,16 @@ public function replaceIframeSources(string $content): string
2821
$content = preg_replace_callback($pattern, function ($matches) {
2922
$beforeSrc = $matches[1];
3023
$iframeUrl = $matches[2];
31-
$afterSrc = $matches[3];
32-
24+
$afterSrc = $matches[3];
25+
3326
// Check if data-cookieconsent already exists
3427
if (preg_match('/data-cookieconsent=["\'][^"\']*["\']/', $beforeSrc . $afterSrc)) {
3528
// If data-cookieconsent already exists, just change src to data-cookieblock-src
3629
return '<iframe' . $beforeSrc . ' data-cookieblock-src="' . $iframeUrl . '"' . $afterSrc . '>';
3730
} else {
3831
// Add data-cookieconsent="marketing" and change src to data-cookieblock-src
39-
return '<iframe' . $beforeSrc . ' data-cookieblock-src="' . $iframeUrl . '" data-cookieconsent="marketing"' . $afterSrc . '>';
32+
return '<iframe' . $beforeSrc . ' data-cookieblock-src="' . $iframeUrl
33+
. '" data-cookieconsent="marketing"' . $afterSrc . '>';
4034
}
4135
}, $content);
4236
}

Plugin/PageBuilder/Model/Filter/TemplatePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TemplatePlugin
2626
*/
2727
public function __construct(Config $config, ExternalVideoReplacer $externalVideoReplacer)
2828
{
29-
$this->config = $config;
29+
$this->config = $config;
3030
$this->externalVideoReplacer = $externalVideoReplacer;
3131
}
3232

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
# CustomGento_Cookiebot
2-
This Magento 2 module integrates Cookiebot into your store. This is useful to give the customer the possibility to block unwanted cookies and only allow wanted cookies. It requires an active Cookiebot subscription and can be completely configured in your Cookiebot account.
2+
3+
This Magento 2 module integrates Cookiebot into your store. This is useful to give the customer the possibility to block
4+
unwanted cookies and only allow wanted cookies. It requires an active Cookiebot subscription and can be completely
5+
configured in your Cookiebot account.
36

47
## Installation
8+
59
- `composer require customgento/module-cookiebot-m2`
610
- `bin/magento module:enable CustomGento_Cookiebot`
711
- `bin/magento setup:upgrade`
812
- `bin/magento setup:di:compile`
913
- `bin/magento cache:flush`
1014

1115
## Configuration
12-
After installing the extension, just go to Stores > Configuration > Web > Cookiebot Settings to enable Cookiebot and enter your Cookiebot ID. You find the ID in your Cookiebot account under Settings > Your scripts. All other configuration regarding the cookie overlay is done in your Cookiebot account.
1316

14-
Please mind that this extension uses the manual cookie blocking mode. Hence, you still need to update all scripts, which set not-strictly-necessary cookies in your system as described in the [Cookiebot manual implementation guide](https://www.cookiebot.com/en/manual-implementation/).
17+
After installing the extension, just go to Stores > Configuration > Web > Cookiebot Settings to enable Cookiebot and
18+
enter your Cookiebot ID. You find the ID in your Cookiebot account under Settings > Your scripts. All other
19+
configuration regarding the cookie overlay is done in your Cookiebot account.
20+
21+
Please mind that this extension uses the manual cookie blocking mode. Hence, you still need to update all scripts, which
22+
set not-strictly-necessary cookies in your system as described in
23+
the [Cookiebot manual implementation guide](https://www.cookiebot.com/en/manual-implementation/).
1524

1625
## Manual vs. Automatic Cookie Blocking
17-
Unfortunately, Cookiebot currently does not support automatic blocking when RequireJS is used as stated in their [docs](https://support.cookiebot.com/hc/en-us/articles/360015039559-Installing-Cookiebot-in-Magento-2-3-4). Since Magento 2 does use RequireJS, we need to use the manual cookie blocking mode :-(
26+
27+
Unfortunately, Cookiebot currently does not support automatic blocking when RequireJS is used as stated in
28+
their [docs](https://support.cookiebot.com/hc/en-us/articles/360015039559-Installing-Cookiebot-in-Magento-2-3-4). Since
29+
Magento 2 does use RequireJS, we need to use the manual cookie blocking mode :-(
1830

1931
## Disclaimer
32+
2033
You need a [Cookiebot](https://www.cookiebot.com/) account, so that this extension does anything useful for you.
2134

2235
## Copyright
36+
2337
&copy; 2020 - present CustomGento GmbH

Test/Unit/Model/ExternalVideoReplacerTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,90 +32,90 @@ public function iframeDataProvider(): array
3232
{
3333
return [
3434
// YouTube test cases
35-
'youtube.com embed' => [
35+
'youtube.com embed' => [
3636
'<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" width="560" height="315"></iframe>',
3737
'<iframe data-cookieblock-src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
3838
],
39-
'youtube-nocookie.com embed' => [
39+
'youtube-nocookie.com embed' => [
4040
'<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ" width="560" height="315"></iframe>',
4141
'<iframe data-cookieblock-src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
4242
],
43-
'youtu.be URL' => [
43+
'youtu.be URL' => [
4444
'<iframe src="https://youtu.be/dQw4w9WgXcQ" width="560" height="315"></iframe>',
4545
'<iframe data-cookieblock-src="https://youtu.be/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
4646
],
47-
'youtube.com without www' => [
47+
'youtube.com without www' => [
4848
'<iframe src="https://youtube.com/embed/dQw4w9WgXcQ" width="560" height="315"></iframe>',
4949
'<iframe data-cookieblock-src="https://youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
5050
],
51-
'youtube-nocookie.com without www' => [
51+
'youtube-nocookie.com without www' => [
5252
'<iframe src="https://youtube-nocookie.com/embed/dQw4w9WgXcQ" width="560" height="315"></iframe>',
5353
'<iframe data-cookieblock-src="https://youtube-nocookie.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
5454
],
55-
'youtu.be without www' => [
55+
'youtu.be without www' => [
5656
'<iframe src="https://youtu.be/dQw4w9WgXcQ" width="560" height="315"></iframe>',
5757
'<iframe data-cookieblock-src="https://youtu.be/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
5858
],
59-
'http instead of https for youtube' => [
59+
'http instead of https for youtube' => [
6060
'<iframe src="http://www.youtube.com/embed/dQw4w9WgXcQ" width="560" height="315"></iframe>',
6161
'<iframe data-cookieblock-src="http://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
6262
],
63-
63+
6464
// Vimeo test cases
65-
'vimeo.com embed' => [
65+
'vimeo.com embed' => [
6666
'<iframe src="https://vimeo.com/123456789" width="640" height="360"></iframe>',
6767
'<iframe data-cookieblock-src="https://vimeo.com/123456789" data-cookieconsent="marketing" width="640" height="360"></iframe>'
6868
],
69-
'player.vimeo.com embed' => [
69+
'player.vimeo.com embed' => [
7070
'<iframe src="https://player.vimeo.com/video/123456789" width="640" height="360"></iframe>',
7171
'<iframe data-cookieblock-src="https://player.vimeo.com/video/123456789" data-cookieconsent="marketing" width="640" height="360"></iframe>'
7272
],
73-
'www.vimeo.com embed' => [
73+
'www.vimeo.com embed' => [
7474
'<iframe src="https://www.vimeo.com/123456789" width="640" height="360"></iframe>',
7575
'<iframe data-cookieblock-src="https://www.vimeo.com/123456789" data-cookieconsent="marketing" width="640" height="360"></iframe>'
7676
],
77-
'www.player.vimeo.com embed' => [
77+
'www.player.vimeo.com embed' => [
7878
'<iframe src="https://www.player.vimeo.com/video/123456789" width="640" height="360"></iframe>',
7979
'<iframe data-cookieblock-src="https://www.player.vimeo.com/video/123456789" data-cookieconsent="marketing" width="640" height="360"></iframe>'
8080
],
81-
'http vimeo' => [
81+
'http vimeo' => [
8282
'<iframe src="http://vimeo.com/123456789" width="640" height="360"></iframe>',
8383
'<iframe data-cookieblock-src="http://vimeo.com/123456789" data-cookieconsent="marketing" width="640" height="360"></iframe>'
8484
],
8585
// General test cases
86-
'single quotes' => [
86+
'single quotes' => [
8787
'<iframe src=\'https://www.youtube.com/embed/dQw4w9WgXcQ\' width="560" height="315"></iframe>',
8888
'<iframe data-cookieblock-src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" width="560" height="315"></iframe>'
8989
],
90-
'multiple iframes different services' => [
90+
'multiple iframes different services' => [
9191
'<iframe src="https://www.youtube.com/embed/video1"></iframe><iframe src="https://vimeo.com/video2"></iframe><iframe src="https://www.google.com/maps/embed?pb=test"></iframe>',
9292
'<iframe data-cookieblock-src="https://www.youtube.com/embed/video1" data-cookieconsent="marketing"></iframe><iframe data-cookieblock-src="https://vimeo.com/video2" data-cookieconsent="marketing"></iframe><iframe src="https://www.google.com/maps/embed?pb=test"></iframe>'
9393
],
94-
'mixed content' => [
94+
'mixed content' => [
9595
'<p>Some text</p><iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe><p>More text</p><iframe src="https://vimeo.com/123456789"></iframe>',
9696
'<p>Some text</p><iframe data-cookieblock-src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing"></iframe><p>More text</p><iframe data-cookieblock-src="https://vimeo.com/123456789" data-cookieconsent="marketing"></iframe>'
9797
],
98-
'iframe with frameborder and allowfullscreen' => [
98+
'iframe with frameborder and allowfullscreen' => [
9999
'<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen=""></iframe>',
100100
'<iframe data-cookieblock-src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing" frameborder="0" allowfullscreen=""></iframe>'
101101
],
102-
'iframe with existing data-cookieconsent' => [
102+
'iframe with existing data-cookieconsent' => [
103103
'<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing"></iframe>',
104104
'<iframe data-cookieblock-src="https://www.youtube.com/embed/dQw4w9WgXcQ" data-cookieconsent="marketing"></iframe>'
105105
],
106106
'iframe with different data-cookieconsent value' => [
107107
'<iframe src="https://vimeo.com/123456789" data-cookieconsent="statistics"></iframe>',
108108
'<iframe data-cookieblock-src="https://vimeo.com/123456789" data-cookieconsent="statistics"></iframe>'
109109
],
110-
'no matching iframe' => [
110+
'no matching iframe' => [
111111
'<iframe src="https://example.com/video"></iframe>',
112112
'<iframe src="https://example.com/video"></iframe>'
113113
],
114-
'no iframe at all' => [
114+
'no iframe at all' => [
115115
'<p>Just some text content</p>',
116116
'<p>Just some text content</p>'
117117
],
118-
'empty content' => [
118+
'empty content' => [
119119
'',
120120
''
121121
]

view/frontend/templates/script.phtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use CustomGento\Cookiebot\ViewModel\Script as CookiebotScriptViewModel;
44
use Magento\Framework\View\Element\Template;
55
use Magento\Framework\View\Helper\SecureHtmlRenderer;
66

7-
/** @var CookiebotScriptViewModel $viewModel */
8-
/** @var SecureHtmlRenderer $secureRenderer */
9-
/** @var Template $block */
7+
/** @var CookiebotScriptViewModel $viewModel */
8+
/** @var SecureHtmlRenderer $secureRenderer */
9+
/** @var Template $block */
1010

11-
$viewModel = $block->getData('view_model')
11+
$viewModel = $block->getData('view_model')
1212
?>
13-
<?= /* @noEscape */ $viewModel->getScript() ?>
13+
<?= /* @noEscape */
14+
$viewModel->getScript() ?>
1415
<?php
1516

1617
if ($viewModel->isGoogleConsentModeEnabled()) {

0 commit comments

Comments
 (0)