Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#85: add newsletter privacy policy checkbox #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php


namespace Opengento\Gdpr\Helper;

use Magento\Framework\Controller\ResultFactory;
use Magento\Store\Model\ScopeInterface;
use Opengento\Gdpr\Model\Config\PrivacyMessage;

class Data extends \Magento\Framework\App\Helper\AbstractHelper {


private const CONFIG_PATH_GENERAL_INFORMATION_PAGE = 'gdpr/general/page_id';
private const CONFIG_PATH_GENERAL_NEWSLETTER_CHECKBOX_LABEL = 'gdpr/general/newsletter_checkbox_label';

private $_helperPage;


public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Cms\Helper\Page $page
)
{
$this->_helperPage = $page;
parent::__construct($context);
}

public function getInformationPageUrl() {

return $this->_helperPage->getPageUrl((string) $this->scopeConfig->getValue(
self::CONFIG_PATH_GENERAL_INFORMATION_PAGE,
ScopeInterface::SCOPE_STORE
)) ?? '#';
}

public function getNewsletterCheckboxLabelConfig() {

return $this->scopeConfig->getValue(self::CONFIG_PATH_GENERAL_NEWSLETTER_CHECKBOX_LABEL,ScopeInterface::SCOPE_STORE);
}

public function getCheckboxLabel() {
return __($this->getNewsletterCheckboxLabelConfig(), $this->getInformationPageUrl());
}



}
17 changes: 17 additions & 0 deletions etc/adminhtml/system/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
</depends>
<config_path>gdpr/general/block_id</config_path>
</field>
<field id="newsletter_checkbox" translate="label comment" type="select" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="50">
<label>Newsletter Checkbox</label>
<comment>Enable Privacy Policy Checkbox Confirm for Magento Newsletter form</comment>
<source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model>
<depends>
<field id="gdpr/general/enabled">1</field>
</depends>
<config_path>gdpr/general/newsletter_checkbox</config_path>
</field>

<field id="newsletter_checkbox_label" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="50">
<label>Newsletter Checkbox Label</label>
<depends>
<field id="gdpr/general/newsletter_checkbox">1</field>
</depends>
<config_path>gdpr/general/newsletter_checkbox_label</config_path>
</field>
</group>
</section>
</include>
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<general>
<enabled>0</enabled>
<page_id>privacy-policy-cookie-restriction-mode</page_id>
<newsletter_checkbox_label><![CDATA[I agree the <a href="%1" title="Privacy Policy">Privacy Policy</a>]]></newsletter_checkbox_label>
</general>
<action>
</action>
Expand Down
3 changes: 3 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,6 @@ ID,ID
State,State
Message,Message
"Privacy Settings","Privacy Settings"
"Newsletter Checkbox Label","Newsletter Checkbox Label"
"Enable Privacy Policy Checkbox Confirm for Magento Newsletter form","Enable Privacy Policy Checkbox Confirm for Magento Newsletter form"
"Newsletter Checkbox","Newsletter Checkbox"
5 changes: 4 additions & 1 deletion i18n/it_IT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,7 @@
"Performed At","Eseguito il"
"State","Stato"
"Message","Messaggio"
"Privacy Settings","Impostazioni Privacy"
"Privacy Settings","Impostazioni Privacy"
"Newsletter Checkbox Label","Label checkbox newsletter"
"Enable Privacy Policy Checkbox Confirm for Magento Newsletter form","Abilita la checkbox per la privacy policy della newsletter di Magento"
"Newsletter Checkbox","Checkbox Newsletter"
5 changes: 5 additions & 0 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
</arguments>
</block>
</referenceContainer>
<referenceBlock name="form.subscribe">
<action method="setTemplate" ifconfig="gdpr/general/newsletter_checkbox">
<argument name="template" xsi:type="string">Opengento_Gdpr::newsletter/subscribe.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
61 changes: 61 additions & 0 deletions view/frontend/templates/newsletter/subscribe.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var \Magento\Newsletter\Block\Subscribe $block */

/** @var \Opengento\Gdpr\Helper\Data $helper */

$helper = $this->helper('Opengento\Gdpr\Helper\Data');

?>
<div class="block newsletter opengento-newsletter">
<div class="title"><strong><?= $block->escapeHtml(__('Newsletter')) ?></strong></div>
<div class="content">
<form class="form subscribe"
novalidate
action="<?= $block->escapeUrl($block->getFormActionUrl()) ?>"
method="post"
data-mage-init='{"validation": {"errorClass": "mage-error"}}'
id="newsletter-validate-detail">
<div class="field newsletter">
<div class="control">
<label for="newsletter">
<span class="label">
<?= $block->escapeHtml(__('Sign Up for Our Newsletter:')) ?>
</span>
<input name="email" type="email" id="newsletter"
placeholder="<?= $block->escapeHtml(__('Enter your email address')) ?>"
data-mage-init='{"mage/trim-input":{}}'
data-validate="{required:true, 'validate-email':true}"
/>
</label>
</div>
<div class="privacy-check">
<input type="checkbox" name="subscribe_checkbox" id="subscribe_checkbox"
data-validate="{required:true}" />
<label for="subscribe_checkbox"><?= $helper->getCheckboxLabel() ?></label>
</div>
</div>
<div class="actions">
<button class="action subscribe primary"
title="<?= $block->escapeHtmlAttr(__('Subscribe')) ?>"
type="submit"
aria-label="Subscribe">
<span><?= $block->escapeHtml(__('Subscribe')) ?></span>
</button>
</div>
</form>
</div>
</div>
<script type="text/x-magento-init">
{
"*": {
"Magento_Customer/js/block-submit-on-send": {
"formId": "newsletter-validate-detail"
}
}
}
</script>
9 changes: 9 additions & 0 deletions view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
}
}
}
.block.newsletter {
.privacy-check {
padding-top: 5px;
input {
height: auto;
padding-left: 0;
}
}
}

.enhanced-privacy-popup {
position: fixed;
Expand Down