Skip to content

Commit

Permalink
Add support for 2.3.x and code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Apr 5, 2019
1 parent 50d08cf commit a79abd3
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 129 deletions.
57 changes: 37 additions & 20 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,56 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
* https://www.magepal.com | [email protected]
*/

namespace MagePal\PreviewCheckoutSuccessPage\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\PreviewCheckoutSuccessPage\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
* @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 +63,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 +77,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 +110,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 +127,7 @@ public function getComposerVersion($moduleName)
$data = json_decode($composerJsonData);
return !empty($data->version) ? $data->version : __('Unknown');
}
} catch (\Exception $e) {
} catch (Exception $e) {
//
}

Expand Down
38 changes: 28 additions & 10 deletions Block/Adminhtml/System/Config/Form/Field/OrderIncrement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
* https://www.magepal.com | [email protected]
*/

/**
Expand All @@ -12,17 +12,35 @@
*/
namespace MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Field;

class OrderIncrement 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\DataObject;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Store\Api\Data\StoreInterface;

/**
* Class OrderIncrement
* @package MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Field
*/
class OrderIncrement extends Field
{

/**
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
* @var CollectionFactory
*/
protected $orderCollectionFactory;

/**
* OrderIncrement constructor.
* @param Context $context
* @param CollectionFactory $orderCollectionFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
Context $context,
CollectionFactory $orderCollectionFactory,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -32,16 +50,16 @@ public function __construct(
/**
* Get the grid and scripts contents
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
$this->setElement($element);

if (!$element->getEscapedValue()) {

/** @var \Magento\Sales\Model\Order $order */
/** @var Order $order */
$order = $this->getLastOrder();

if ($order->getId()) {
Expand All @@ -53,7 +71,7 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
}

/**
* @return \Magento\Store\Api\Data\StoreInterface|null
* @return StoreInterface|null
*/
public function getCurrentStore()
{
Expand All @@ -70,7 +88,7 @@ public function getCurrentStore()
}

/**
* @return \Magento\Framework\DataObject
* @return DataObject
*/
public function getLastOrder()
{
Expand Down
33 changes: 19 additions & 14 deletions Block/Adminhtml/System/Config/Form/Field/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
* https://www.magepal.com | [email protected]
*/

namespace MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\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\Url;
use Magento\Store\Api\Data\StoreInterface;

/**
* Class Locations Backend system config array field renderer
* Class Preview
* @package MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Field
*/
class Preview extends Field
{
Expand All @@ -20,19 +25,19 @@ class Preview extends Field
protected $_template = 'MagePal_PreviewCheckoutSuccessPage::system/config/form/field/preview.phtml';

/**
* @var \Magento\Framework\Url
* @var Url
*/
protected $urlHelper;

/**
* Preview constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Url $urlHelper
* @param Context $context
* @param Url $urlHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Url $urlHelper,
Context $context,
Url $urlHelper,
array $data = []
) {
$this->urlHelper = $urlHelper;
Expand All @@ -41,10 +46,10 @@ public function __construct(


/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();

Expand All @@ -54,29 +59,29 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
protected function _renderValue(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _renderValue(AbstractElement $element)
{
return $this->_getElementHtml($element);
}

/**
* Get the grid and scripts contents
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
protected function _getElementHtml(AbstractElement $element)
{
$this->setElement($element);

return $this->_toHtml();
}

/**
* @return \Magento\Store\Api\Data\StoreInterface|null
* @return StoreInterface|null
*/
public function getCurrentStore()
{
Expand Down
34 changes: 22 additions & 12 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
* https://www.magepal.com | [email protected]
*/

namespace MagePal\PreviewCheckoutSuccessPage\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\PreviewCheckoutSuccessPage\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
* @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 +42,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 +56,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
Loading

0 comments on commit a79abd3

Please sign in to comment.