Skip to content

Commit 4b54a23

Browse files
committed
MAGETWO-32907: Move Magento_Theme Cookie code to Magento_Cookie
- Moved out cookie notices template and configurations out of Theme module - Added new Notices block and injected to the global notices - Moved js and requirejs related configs from Theme module
1 parent 2e08688 commit 4b54a23

File tree

9 files changed

+78
-44
lines changed

9 files changed

+78
-44
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Frontend form key content block
9+
*/
10+
namespace Magento\Cookie\Block\Html;
11+
12+
class Notices extends \Magento\Framework\View\Element\Template
13+
{
14+
/**
15+
* Get Link to cookie restriction privacy policy page
16+
*
17+
* @return string
18+
*/
19+
public function getPrivacyPolicyLink()
20+
{
21+
return $this->_urlBuilder->getUrl('privacy-policy-cookie-restriction-mode');
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="after.body.start">
11+
<block class="Magento\Cookie\Block\Html\Notices" name="cookie_notices" template="html/notices.phtml" after="global_notices" />
12+
</referenceContainer>
13+
</body>
14+
</page>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
<?php /** @var \Magento\Cookie\Block\Html\Notices $this */ ?>
8+
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isUserNotAllowSaveCookie()): ?>
9+
<div class="message global cookie" id="notice-cookie-block" style="display: none">
10+
<div class="content">
11+
<p>
12+
<strong><?php echo __('We use cookies to make your experience better.') ?></strong>
13+
<span><?php echo __('To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies.') ?></span>
14+
<?php echo __('<a href="%1">Learn more</a>.', $this->getPrivacyPolicyLink()) ?></p>
15+
<div class="actions">
16+
<button id="btn-cookie-allow" class="action allow primary">
17+
<span><?php echo __('Allow Cookies');?></span>
18+
</button>
19+
</div>
20+
</div>
21+
</div>
22+
<script>
23+
require([
24+
"jquery",
25+
"mage/mage"
26+
], function($){
27+
28+
// <![CDATA[
29+
$('#notice-cookie-block').mage('cookieBlock', {
30+
cookieAllowButtonSelector: '#btn-cookie-allow',
31+
cookieName: '<?php echo \Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE ?>',
32+
cookieValue: '<?php echo $this->helper('Magento\Cookie\Helper\Cookie')->getAcceptedSaveCookiesWebsiteIds() ?>',
33+
cookieLifetime: <?php echo $this->helper('Magento\Cookie\Helper\Cookie')->getCookieRestrictionLifetime()?>,
34+
noCookiesUrl: '<?php echo $this->getUrl('cookie/index/noCookies') ?>'
35+
});
36+
// ]]>
37+
38+
});
39+
</script>
40+
<?php endif; ?>

app/code/Magento/Theme/Block/Html/Notices.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,4 @@ public function displayDemoNotice()
5757
\Magento\Framework\Store\ScopeInterface::SCOPE_STORE
5858
);
5959
}
60-
61-
/**
62-
* Get Link to cookie restriction privacy policy page
63-
*
64-
* @return string
65-
*/
66-
public function getPrivacyPolicyLink()
67-
{
68-
return $this->_urlBuilder->getUrl('privacy-policy-cookie-restriction-mode');
69-
}
7060
}

app/code/Magento/Theme/view/frontend/requirejs-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var config = {
77
map: {
88
"*": {
9-
"cookieBlock": "Magento_Theme/js/notices",
9+
"cookieBlock": "Magento_Cookie/js/notices",
1010
"rowBuilder": "Magento_Theme/js/row-builder",
1111
"toggleAdvanced": "mage/toggle",
1212
"translateInline": "mage/translate-inline",

app/code/Magento/Theme/view/frontend/templates/html/notices.phtml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,3 @@ require(['jquery'], function(jQuery){
5858
</div>
5959
</div>
6060
<?php endif; ?>
61-
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isUserNotAllowSaveCookie()): ?>
62-
<div class="message global cookie" id="notice-cookie-block" style="display: none">
63-
<div class="content">
64-
<p>
65-
<strong><?php echo __('We use cookies to make your experience better.') ?></strong>
66-
<span><?php echo __('To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies.') ?></span>
67-
<?php echo __('<a href="%1">Learn more</a>.', $this->getPrivacyPolicyLink()) ?></p>
68-
<div class="actions">
69-
<button id="btn-cookie-allow" class="action allow primary">
70-
<span><?php echo __('Allow Cookies');?></span>
71-
</button>
72-
</div>
73-
</div>
74-
</div>
75-
<script>
76-
require([
77-
"jquery",
78-
"mage/mage"
79-
], function($){
80-
81-
// <![CDATA[
82-
$('#notice-cookie-block').mage('cookieBlock', {
83-
cookieAllowButtonSelector: '#btn-cookie-allow',
84-
cookieName: '<?php echo \Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE ?>',
85-
cookieValue: '<?php echo $this->helper('Magento\Cookie\Helper\Cookie')->getAcceptedSaveCookiesWebsiteIds() ?>',
86-
cookieLifetime: <?php echo $this->helper('Magento\Cookie\Helper\Cookie')->getCookieRestrictionLifetime()?>,
87-
noCookiesUrl: '<?php echo $this->getUrl('cookie/index/noCookies') ?>'
88-
});
89-
// ]]>
90-
91-
});
92-
</script>
93-
<?php endif; ?>

0 commit comments

Comments
 (0)