Skip to content

Commit 3ec0a09

Browse files
author
Michele Fantetti aka WaPoNe
committed
First commit
0 parents  commit 3ec0a09

18 files changed

+687
-0
lines changed

Block/CookieNotification.php

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* WaPoNe
4+
*
5+
* @category WaPoNe
6+
* @package WaPoNe_CookieNotification
7+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
8+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9+
*/
10+
11+
namespace WaPoNe\CookieNotification\Block;
12+
13+
class CookieNotification extends \Magento\Framework\View\Element\Template
14+
{
15+
protected $_dataHelper;
16+
protected $_storeManager;
17+
18+
public function __construct(
19+
\Magento\Framework\View\Element\Template\Context $context,
20+
\WaPoNe\CookieNotification\Helper\Data $dataHelper,
21+
\Magento\Store\Model\StoreManagerInterface $storeManager,
22+
array $data)
23+
{
24+
$this->_dataHelper = $dataHelper;
25+
$this->_storeManager = $storeManager;
26+
parent::__construct($context, $data);
27+
}
28+
29+
public function _prepareLayout()
30+
{
31+
return parent::_prepareLayout();
32+
}
33+
34+
// Module Activation
35+
public function getModuleActivation() {
36+
return $this->_dataHelper->getConfig('cookienotification/functional/activation');
37+
}
38+
39+
// Cookie Name
40+
public function getCookieName() {
41+
return "wapone_cookienotification";
42+
}
43+
44+
// Cookie Lifetime
45+
public function getCookieLifetime() {
46+
return $this->_dataHelper->getConfig('cookienotification/functional/lifetime');
47+
}
48+
49+
// Cookie Path
50+
public function getCookiePath() {
51+
return $this->_dataHelper->getConfig('cookienotification/functional/path');
52+
}
53+
54+
// Cookie Domain
55+
public function getCookieDomain() {
56+
return $this->_dataHelper->getConfig('cookienotification/functional/domain');
57+
}
58+
59+
// Cookie Message
60+
public function getCookieMessage() {
61+
return $this->_dataHelper->getConfig('cookienotification/design/message');
62+
}
63+
64+
public function getCookieMessageTextColor() {
65+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/message_text_color');
66+
}
67+
68+
public function getCookieMessageBackgroundColor() {
69+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/message_background_color');
70+
}
71+
72+
public function getCookieMoreButtonText() {
73+
return $this->_dataHelper->getConfig('cookienotification/design/btn_more_text');
74+
}
75+
76+
public function getCookieMoreButtonTextColor() {
77+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/btn_more_text_color');
78+
}
79+
80+
public function getCookieMoreButtonLink() {
81+
return $this->_dataHelper->getConfig('cookienotification/design/btn_more_link');
82+
}
83+
84+
public function getCookieMoreButtonLinkDestination() {
85+
return $this->_dataHelper->getConfig('cookienotification/design/btn_more_link_destination');
86+
}
87+
88+
public function getCookieMoreButtonBackgroundColor() {
89+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/btn_more_background_color');
90+
}
91+
92+
public function getCookieAllowButtonText() {
93+
return $this->_dataHelper->getConfig('cookienotification/design/btn_allow_text');
94+
}
95+
96+
public function getCookieAllowButtonTextColor() {
97+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/btn_allow_text_color');
98+
}
99+
100+
public function getCookieAllowButtonBackgroundColor() {
101+
return '#'.$this->_dataHelper->getConfig('cookienotification/design/btn_allow_background_color');
102+
}
103+
104+
public function getCookiePosition() {
105+
switch ($this->_dataHelper->getConfig('cookienotification/design/position')) {
106+
case 'top': return 'top: 0;';
107+
case 'bottom': return 'bottom: 0;';
108+
default : return 'top: 0;';
109+
}
110+
}
111+
}

Helper/Data.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* WaPoNe
4+
*
5+
* @category WaPoNe
6+
* @package WaPoNe_CookieNotification
7+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
8+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9+
*/
10+
11+
namespace WaPoNe\CookieNotification\Helper;
12+
13+
class Data extends \Magento\Framework\App\Helper\AbstractHelper
14+
{
15+
public function getConfig($config_path)
16+
{
17+
return $this->scopeConfig->getValue($config_path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
18+
}
19+
}

Model/Config/Backend/CMSPageList.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* WaPoNe
4+
*
5+
* @category WaPoNe
6+
* @package WaPoNe_CookieNotification
7+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
8+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9+
*/
10+
11+
namespace WaPoNe\CookieNotification\Model\Config\Backend;
12+
13+
class CMSPageList implements \Magento\Framework\Option\ArrayInterface
14+
{
15+
protected $_pageCollectionFactory;
16+
17+
public function __construct(
18+
\Magento\Cms\Model\ResourceModel\Page\CollectionFactory $pageCollectionFactory
19+
)
20+
{
21+
$this->_pageCollectionFactory = $pageCollectionFactory;
22+
}
23+
24+
public function toOptionArray()
25+
{
26+
$arr = $this->_toArray();
27+
$ret = [];
28+
29+
foreach ($arr as $key => $value)
30+
{
31+
$ret[] = [
32+
'value' => $key,
33+
'label' => $value
34+
];
35+
}
36+
37+
return $ret;
38+
}
39+
40+
// List of all CMS Pages
41+
private function _toArray()
42+
{
43+
$pages = $this->_pageCollectionFactory->create();
44+
$pageList = array();
45+
46+
foreach ($pages as $page)
47+
{
48+
// identifier => url-alias
49+
$pageList[$page->getIdentifier()] = __($page->getTitle());
50+
}
51+
52+
return $pageList;
53+
}
54+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* WaPoNe
4+
*
5+
* @category WaPoNe
6+
* @package WaPoNe_CookieNotification
7+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
8+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9+
*/
10+
11+
namespace WaPoNe\CookieNotification\Model\Config\Backend;
12+
13+
class LinkDestination implements \Magento\Framework\Option\ArrayInterface
14+
{
15+
public function toOptionArray()
16+
{
17+
$destination = array();
18+
19+
$destination[] = [
20+
'value' => 1,
21+
'label' => __('Same Frame')
22+
];
23+
$destination[] = [
24+
'value' => 2,
25+
'label' => __('New Window')
26+
];
27+
28+
return $destination;
29+
}
30+
}

Model/Config/Backend/Position.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* WaPoNe
4+
*
5+
* @category WaPoNe
6+
* @package WaPoNe_CookieNotification
7+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
8+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9+
*/
10+
11+
namespace WaPoNe\CookieNotification\Model\Config\Backend;
12+
13+
class Position implements \Magento\Framework\Option\ArrayInterface
14+
{
15+
public function toOptionArray()
16+
{
17+
$position = array();
18+
19+
$position[] = [
20+
'value' => 'top',
21+
'label' => __('Top')
22+
];
23+
$position[] = [
24+
'value' => 'bottom',
25+
'label' => __('Bottom')
26+
];
27+
28+
return $position;
29+
}
30+
}

composer.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "wapone/module-cookie-notification",
3+
"description": "Magento 2 extension to inform users about use and management of your website cookies",
4+
"type": "magento2-module",
5+
"version": "0.0.1",
6+
"license": [
7+
"OSL-3.0",
8+
"AFL-3.0"
9+
],
10+
"require": {
11+
"php": "~5.5.0|~5.6.0|~7.0.0",
12+
"wapone/base": "*"
13+
},
14+
"authors": [{
15+
"name": "WaPoNe",
16+
"email": "[email protected]",
17+
"homepage": "http://www.fantetti.net",
18+
"role": "Developer"
19+
}],
20+
"autoload": {
21+
"files": ["registration.php"],
22+
"psr-4": {
23+
"WaPoNe\\CookieNotification\\": ""
24+
}
25+
}
26+
}

etc/adminhtml/system.xml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* WaPoNe
5+
*
6+
* @category WaPoNe
7+
* @package WaPoNe_CookieNotification
8+
* @copyright Copyright (c) 2017 WaPoNe (http://www.fantetti.net)
9+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10+
*/
11+
-->
12+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
14+
<system>
15+
<section id="cookienotification" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
16+
<label>Cookie Notification</label>
17+
<tab>wapone</tab>
18+
<resource>WaPoNe_CookieNotification::config_cookienotification</resource>
19+
<group id="functional" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
20+
<label>Functional Settings</label>
21+
<field id="activation" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
22+
<label>Enable Module</label>
23+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
24+
<comment>Enable / disable module</comment>
25+
</field>
26+
<field id="lifetime" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
27+
<label>Cookie Lifetime</label>
28+
<validate>validate-number</validate>
29+
<comment>Default value is 3600</comment>
30+
</field>
31+
<field id="path" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
32+
<label>Cookie Path</label>
33+
</field>
34+
<field id="domain" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
35+
<label>Cookie Domain</label>
36+
</field>
37+
</group>
38+
<group id="design" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
39+
<label>Design Settings</label>
40+
<field id="position" translate="label comment" type="radios" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
41+
<label>Message Position</label>
42+
<source_model>WaPoNe\CookieNotification\Model\Config\Backend\Position</source_model>
43+
<comment>Where the cookie message should appear</comment>
44+
</field>
45+
<field id="message" translate="label" type="textarea" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
46+
<label>Message</label>
47+
</field>
48+
<field id="message_text_color" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
49+
<label>Message Text Color</label>
50+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
51+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
52+
</field>
53+
<field id="message_background_color" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
54+
<label>Message Background Color</label>
55+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
56+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
57+
</field>
58+
<field id="btn_more_text" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
59+
<label>Cookie More Button Text</label>
60+
</field>
61+
<field id="btn_more_text_color" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
62+
<label>Cookie More Button Text Color</label>
63+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
64+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
65+
</field>
66+
<field id="btn_more_background_color" translate="label comment" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
67+
<label>Cookie More Button Background Color</label>
68+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
69+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
70+
</field>
71+
<field id="btn_more_link" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
72+
<label>Cookie More Button Link</label>
73+
<source_model>WaPoNe\CookieNotification\Model\Config\Backend\CMSPageList</source_model>
74+
</field>
75+
<field id="btn_more_link_destination" translate="label comment" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
76+
<label>Cookie More Button Link Destination</label>
77+
<source_model>WaPoNe\CookieNotification\Model\Config\Backend\LinkDestination</source_model>
78+
<validate>validate-select</validate>
79+
<comment>
80+
<![CDATA[<br />
81+
<strong>Same Frame</strong>: Opens the window in the same frame, it means existing window itself.<br />
82+
<strong>New Window</strong>: Opens a new window and show the related data.
83+
]]>
84+
</comment>
85+
</field>
86+
<field id="btn_allow_text" translate="label" type="text" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
87+
<label>Cookie Allow Button Text</label>
88+
</field>
89+
<field id="btn_allow_text_color" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
90+
<label>Cookie Allow Button Text Color</label>
91+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
92+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
93+
</field>
94+
<field id="btn_allow_background_color" translate="label comment" type="text" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
95+
<label>Cookie Allow Button Background Color</label>
96+
<validate>validate-exadecimal-color-length validate-alphanum</validate>
97+
<comment>Exadecimal value, without #: ex. FFFFFF</comment>
98+
</field>
99+
</group>
100+
</section>
101+
</system>
102+
</config>

0 commit comments

Comments
 (0)