Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Apr 15, 2019
1 parent 93d2e48 commit f0af7c5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 46 deletions.
56 changes: 37 additions & 19 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,52 @@

namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer;

class Version extends \Magento\Config\Block\System\Config\Form\Field
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Phrase;

/**
* Class Version
* @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer
*/
class Version extends Field
{

/**
* @var \Magento\Framework\App\DeploymentConfig
* @var DeploymentConfig
*/
protected $deploymentConfig;

/**
* @var \Magento\Framework\Component\ComponentRegistrarInterface
* @var ComponentRegistrarInterface
*/
protected $componentRegistrar;

/**
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
* @var ReadFactory
*/
protected $readFactory;

/**
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
* Version constructor.
* @param Context $context
* @param DeploymentConfig $deploymentConfig
* @param ComponentRegistrarInterface $componentRegistrar
* @param ReadFactory $readFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
Context $context,
DeploymentConfig $deploymentConfig,
ComponentRegistrarInterface $componentRegistrar,
ReadFactory $readFactory,
array $data = []
) {
$this->deploymentConfig = $deploymentConfig;
Expand All @@ -46,11 +64,11 @@ public function __construct(
/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
Expand All @@ -60,11 +78,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->getVersion();
}
Expand Down Expand Up @@ -93,12 +111,12 @@ public function getModuleName()
* Get module composer version
*
* @param $moduleName
* @return \Magento\Framework\Phrase|string|void
* @return Phrase|string|void
*/
public function getComposerVersion($moduleName)
{
$path = $this->componentRegistrar->getPath(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
ComponentRegistrar::MODULE,
$moduleName
);

Expand All @@ -110,7 +128,7 @@ public function getComposerVersion($moduleName)
$data = json_decode($composerJsonData);
return !empty($data->version) ? $data->version : __('Unknown');
}
} catch (\Exception $e) {
} catch (Exception $e) {
//
}

Expand Down
34 changes: 23 additions & 11 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,34 @@

namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module;

class Version extends \Magento\Config\Block\System\Config\Form\Field
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Module\ModuleListInterface;

/**
* Class Version
* @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module
*/
class Version extends Field
{

/**
* @var \Magento\Framework\Module\ModuleListInterface
* @var ModuleListInterface
*/
protected $_moduleList;


/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* Version constructor.
* @param Context $context
* @param ModuleListInterface $moduleList
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Module\ModuleListInterface $moduleList,
Context $context,
ModuleListInterface $moduleList,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -32,11 +44,11 @@ public function __construct(
/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
Expand All @@ -46,11 +58,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
return 'v' . $this->getVersion();
}
Expand Down
13 changes: 10 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
*/

namespace MagePal\NewsletterSignupEmail\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;

/**
* Class Data
* @package MagePal\NewsletterSignupEmail\Helper
*/
class Data extends AbstractHelper
{
const XML_PATH_ACTIVE = 'newsletter_signup_email/general/active';

Expand All @@ -20,7 +27,7 @@ public function isEnabled()
{
return !$this->scopeConfig->isSetFlag(
self::XML_PATH_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
ScopeInterface::SCOPE_STORE
);
}
}
26 changes: 15 additions & 11 deletions Plugin/Model/SubscriberPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,53 @@
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\NewsletterSignupEmail\Plugin\Model;

use Magento\Newsletter\Model\Subscriber;
use MagePal\NewsletterSignupEmail\Helper\Data;

class SubscriberPlugin
{

/** @var \MagePal\NewsletterSignupEmail\Helper\Data */
/** @var Data */
protected $helper;

public function __construct(
\MagePal\NewsletterSignupEmail\Helper\Data $helper
Data $helper
) {
$this->helper = $helper;
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param Subscriber $subject
* @param callable $proceed
*/
public function aroundSendUnsubscriptionEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
public function aroundSendUnsubscriptionEmail(Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
if ($this->helper->isEnabled()) {
$proceed();
}
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param Subscriber $subject
* @param callable $proceed
*/
public function aroundSendConfirmationRequestEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
public function aroundSendConfirmationRequestEmail(Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
if ($this->helper->isEnabled()) {
$proceed();
}
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param Subscriber $subject
* @param callable $proceed
*/
public function aroundSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
public function aroundSendConfirmationSuccessEmail(Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
if ($this->helper->isEnabled()) {
$proceed();
}
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
],
"require": {
"php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.1.3|~7.2.0",
"magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.0",
"magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*",
"magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*",
"magento/module-newsletter": "*"
},
"type": "magento2-module",
"version": "1.1.1",
"version": "1.1.2",
"autoload": {
"files": [
"registration.php"
Expand Down

0 comments on commit f0af7c5

Please sign in to comment.