Skip to content

Commit

Permalink
Add possibility to select banner position
Browse files Browse the repository at this point in the history
  • Loading branch information
williankeller authored May 17, 2019
1 parent 9070be0 commit 8365334
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 76 deletions.
63 changes: 43 additions & 20 deletions Block/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* A Magento 2 module named Magestat/CookieLawBanner
* Copyright (C) 2018 Magestat
*
* This file included in Magestat/CookieLawBanner is licensed under OSL 3.0
*
Expand Down Expand Up @@ -64,21 +63,17 @@ public function getIsEnabled()
/**
* Retrieve banner title.
*
* @return string
* @return null|string
*/
public function getTitle()
{
$title = $this->helperData->getTitle();
if (empty($title)) {
return false;
}
return $title;
return $this->helperData->getTitle();
}

/**
* Retrieve banner message content.
*
* @return string
* @return null|string
*/
public function getMessage()
{
Expand All @@ -88,29 +83,21 @@ public function getMessage()
/**
* Retrieve banner more info text.
*
* @return string
* @return null|string
*/
public function getInfoMessage()
{
$info = $this->helperData->getInfoMessage();
if (empty($info)) {
return false;
}
return $info;
return $this->helperData->getInfoMessage();
}

/**
* Retrieve banner more info link to.
*
* @return string
* @return null|string
*/
public function getInfoLink()
{
$link = $this->helperData->getInfoLink();
if (empty($link)) {
return false;
}
return $link;
return $this->helperData->getInfoLink();
}

/**
Expand All @@ -126,4 +113,40 @@ public function getButton()
}
return $button;
}

/**
* Responsible to vuild the style classes together.
*
* @return string
*/
public function getAdditionalStyle()
{
return $this->getPosition() . $this->getDefaultStyle();
}

/**
* Retrieve banner place position.
*
* @return string
*/
private function getPosition()
{
$position = $this->helperData->getPosition();
if (empty($position)) {
return 'bottom-left';
}
return $position;
}

/**
* Return class to apply default style from Magento.
*
* @return string
*/
private function getDefaultStyle()
{
if ($this->helperData->isDefaultStyle()) {
return ' default-style';
}
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.

### [1.0.4](https://github.com/magestat/magento2-cookie-law-banner/releases/tag/1.0.4) - 2019-05-17
#### Added
- Possibility to select banner position.
- Full banner at the top and bottom.
- Possibility to use Magento default banner style.

#### Improved
- Methods responses.
- Get Url action (using default magento method).

### [1.0.3](https://github.com/magestat/magento2-cookie-law-banner/releases/tag/1.0.3) - 2019-04-04
#### Improved
- Add compatibility with PHP 7.2
Expand Down
65 changes: 43 additions & 22 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
namespace Magestat\CookieLawBanner\Helper;

/**
* @package \Magestat\CookieLawBanner\Helper
* Class Data
* @package Magestat\CookieLawBanner\Helper
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
Expand All @@ -24,79 +25,99 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
public function isActive()
{
return (bool) $this->getConfigValue(
'magestat_cookielawbanner/module/enabled'
return (bool) $this->scopeConfig->isSetFlag(
'magestat_cookielawbanner/module/enabled',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve banner title.
*
* @return string
* @return null|string
*/
public function getTitle()
{
return $this->getConfigValue(
'magestat_cookielawbanner/general/title'
return $this->scopeConfig->getValue(
'magestat_cookielawbanner/general/title',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve banner message content.
*
* @return string
* @return null|string
*/
public function getMessage()
{
return $this->getConfigValue(
'magestat_cookielawbanner/general/message'
return $this->scopeConfig->getValue(
'magestat_cookielawbanner/general/message',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve banner more info text.
*
* @return string
* @return null|string
*/
public function getInfoMessage()
{
return $this->getConfigValue(
'magestat_cookielawbanner/general/details'
return $this->scopeConfig->getValue(
'magestat_cookielawbanner/general/details',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve banner more info link to.
*
* @return string
* @return null|string
*/
public function getInfoLink()
{
return $this->getConfigValue(
'magestat_cookielawbanner/general/link'
return $this->scopeConfig->getValue(
'magestat_cookielawbanner/general/link',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve banner accept button text.
*
* @return string
* @return null|string
*/
public function getButton()
{
return $this->getConfigValue(
'magestat_cookielawbanner/general/button'
return $this->scopeConfig->getValue(
'magestat_cookielawbanner/general/button',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @param string $path
* @return string
* Retrieve banner accept button text.
*
* @return null|string
*/
public function getConfigValue($path)
public function getPosition()
{
return $this->scopeConfig->getValue(
$path,
'magestat_cookielawbanner/layout/position',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Check if module is active.
*
* @return bool
*/
public function isDefaultStyle()
{
return (bool) $this->scopeConfig->isSetFlag(
'magestat_cookielawbanner/layout/default',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
Expand Down
53 changes: 53 additions & 0 deletions Model/Config/Source/BannerPosition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* A Magento 2 module named Magestat/CookieLawBanner
*
* This file included in Magestat/CookieLawBanner is licensed under OSL 3.0
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
*/

namespace Magestat\CookieLawBanner\Model\Config\Source;

/**
* Class ButtonPosition
* @package Magestat\CookieLawBanner\Model\Config\Source
*/
class BannerPosition implements \Magento\Framework\Option\ArrayInterface
{
/**
* Get options as array
*
* @return array
*/
public function toOptionArray()
{
return [
[
'value' => 'bottom-right',
'label' => __('Footer Right Block')
],
[
'value' => 'bottom-left',
'label' => __('Footer Left Block')
],
[
'value' => 'bottom-full',
'label' => __('Footer Full Banner')
],
[
'value' => 'top-right',
'label' => __('Head Right Block')
],
[
'value' => 'top-left',
'label' => __('Head Left Block')
],
[
'value' => 'top-full',
'label' => __('Head Full Banner')
]
];
}
}
1 change: 0 additions & 1 deletion Model/CookieHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* A Magento 2 module named Magestat/CookieLawBanner
* Copyright (C) 2018 Magestat
*
* This file included in Magestat/CookieLawBanner is licensed under OSL 3.0
*
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magestat/module-cookie-law-banner",
"description": "This extension allows your enable an EU compliant consent cookie notification banner.",
"description": "This extension allows you enable an EU compliant consent cookie notification banner.",
"keywords": [
"magento 2",
"cookie law banner",
Expand All @@ -10,7 +10,7 @@
"magento 2 cookie"
],
"type": "magento2-module",
"version": "1.0.3",
"version": "1.0.4",
"support": {
"issues": "https://github.com/magestat/magento2-cookie-law-banner/issues/"
},
Expand Down
22 changes: 18 additions & 4 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!--
/**
* A Magento 2 module named Magestat/CookieLawBanner
* Copyright (C) 2018 Magestat
*
* This file included in Magestat/CookieLawBanner is licensed under OSL 3.0
*
Expand All @@ -27,23 +26,38 @@
</field>
</group>
<group id="general" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="20" translate="label">
<label>Settings</label>
<label>Content Management</label>
<field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
</field>
<field id="message" translate="label" type="textarea" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Small Cookies Description</label>
<label>Cookies Introduction</label>
</field>
<field id="details" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>More Details Text</label>
<comment>This is the text to take your customer to the Cookie Policy page.</comment>
</field>
<field id="link" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>More Details Link of Text</label>
<label>Cookie Page URL</label>
<comment>You can use the Magento default page our a external page.</comment>
</field>
<field id="button" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Accept Button Text</label>
</field>
</group>
<group id="layout" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="30" translate="label">
<label>Layout Configuration</label>
<field id="position" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Position to be Displayed</label>
<frontend_class>positions</frontend_class>
<source_model>Magestat\CookieLawBanner\Model\Config\Source\BannerPosition</source_model>
</field>
<field id="default" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use Default Layout From Magento</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>This option allow you use the same font size and background color from Default magento Cookie Restriction banner.</comment>
</field>
</group>
</section>
</system>
</config>
Loading

0 comments on commit 8365334

Please sign in to comment.