Skip to content

Use constructor property promotion in module Variable #37022

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

Open
wants to merge 3 commits into
base: 2.4-develop
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
4 changes: 3 additions & 1 deletion app/code/Magento/Variable/Block/System/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/
namespace Magento\Variable\Block\System;

use Magento\Backend\Block\Widget\Grid\Container;

/**
* Custom Variable Block
*
* @api
* @since 100.0.2
*/
class Variable extends \Magento\Backend\Block\Widget\Grid\Container
class Variable extends Container
{
/**
* Block constructor
Expand Down
26 changes: 16 additions & 10 deletions app/code/Magento/Variable/Block/System/Variable/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@
*/
namespace Magento\Variable\Block\System\Variable;

use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Phrase;
use Magento\Framework\Registry;
use Magento\Variable\Model\Variable;

/**
* Custom Variable Edit Container
*
* @api
* @since 100.0.2
*/
class Edit extends \Magento\Backend\Block\Widget\Form\Container
class Edit extends Container
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
* @var Registry
*/
protected $_coreRegistry = null;

/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param Context $context
* @param Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
Context $context,
Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
Expand All @@ -51,7 +55,7 @@ protected function _construct()
/**
* Getter
*
* @return \Magento\Variable\Model\Variable
* @return Variable
*/
public function getVariable()
{
Expand All @@ -60,6 +64,7 @@ public function getVariable()

/**
* Prepare layout.
*
* Adding save_and_continue button
*
* @return $this
Expand Down Expand Up @@ -87,6 +92,7 @@ protected function _preparelayout()
* Return form HTML
*
* @return string
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
*/
public function getFormHtml()
{
Expand All @@ -96,7 +102,7 @@ public function getFormHtml()
/**
* Return translated header text depending on creating/editing action
*
* @return \Magento\Framework\Phrase
* @return Phrase
*/
public function getHeaderText()
{
Expand Down
12 changes: 8 additions & 4 deletions app/code/Magento/Variable/Block/System/Variable/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
*/
namespace Magento\Variable\Block\System\Variable\Edit;

use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Framework\Data\Form as FormData;
use Magento\Variable\Model\Variable;

/**
* Custom Variable Edit Form
*
* @api
* @since 100.0.2
*/
class Form extends \Magento\Backend\Block\Widget\Form\Generic
class Form extends Generic
{
/**
* Getter
*
* @return \Magento\Variable\Model\Variable
* @return Variable
*/
public function getVariable()
{
Expand All @@ -26,11 +30,11 @@ public function getVariable()
/**
* Prepare form before rendering HTML
*
* @return \Magento\Variable\Block\System\Variable\Edit\Form
* @return Form
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
/** @var FormData $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);
Expand Down
72 changes: 27 additions & 45 deletions app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
namespace Magento\Variable\Controller\Adminhtml\System;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\ForwardFactory;
use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutFactory;
use Magento\Framework\View\Result\PageFactory;
use Magento\Variable\Model\Variable as ModelVariable;

/**
* Custom Variables admin controller
Expand All @@ -17,67 +25,41 @@ abstract class Variable extends Action
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Variable::variable';
public const ADMIN_RESOURCE = 'Magento_Variable::variable';

/**
* Core registry
*
* @var \Magento\Framework\Registry
* @var Registry
*/
protected $_coreRegistry;

/**
* @var \Magento\Backend\Model\View\Result\ForwardFactory
*/
protected $resultForwardFactory;

/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;

/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;

/**
* @var \Magento\Framework\View\LayoutFactory
*/
protected $layoutFactory;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param Context $context
* @param Registry $coreRegistry
* @param ForwardFactory $resultForwardFactory
* @param JsonFactory $resultJsonFactory
* @param PageFactory $resultPageFactory
* @param LayoutFactory $layoutFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory
Context $context,
Registry $coreRegistry,
protected readonly ForwardFactory $resultForwardFactory,
protected readonly JsonFactory $resultJsonFactory,
protected readonly PageFactory $resultPageFactory,
protected readonly LayoutFactory $layoutFactory
) {
$this->_coreRegistry = $coreRegistry;
parent::__construct($context);
$this->resultForwardFactory = $resultForwardFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->resultPageFactory = $resultPageFactory;
$this->layoutFactory = $layoutFactory;
}

/**
* Initialize Layout and set breadcrumbs
*
* @return \Magento\Backend\Model\View\Result\Page
* @return Page
*/
protected function createPage()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
/** @var Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Magento_Variable::system_variable')
->addBreadcrumb(__('Custom Variables'), __('Custom Variables'));
Expand All @@ -87,14 +69,14 @@ protected function createPage()
/**
* Initialize Variable object
*
* @return \Magento\Variable\Model\Variable
* @return ModelVariable
*/
protected function _initVariable()
{
$variableId = $this->getRequest()->getParam('variable_id', null);
$storeId = (int)$this->getRequest()->getParam('store', 0);
/* @var $variable \Magento\Variable\Model\Variable */
$variable = $this->_objectManager->create(\Magento\Variable\Model\Variable::class);
/* @var ModelVariable $variable */
$variable = $this->_objectManager->create(ModelVariable::class);
if ($variableId) {
$variable->setStoreId($storeId)->load($variableId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
*/
namespace Magento\Variable\Controller\Adminhtml\System\Variable;

class Delete extends \Magento\Variable\Controller\Adminhtml\System\Variable
use Exception;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Variable\Controller\Adminhtml\System\Variable;

class Delete extends Variable implements HttpPostActionInterface
{
/**
* Delete Action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @return Redirect
*/
public function execute()
{
$variable = $this->_initVariable();
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($variable->getId()) {
try {
$variable->delete();
$this->messageManager->addSuccess(__('You deleted the custom variable.'));
} catch (\Exception $e) {
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
return $resultRedirect->setPath('adminhtml/*/edit', ['_current' => true]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
*/
namespace Magento\Variable\Controller\Adminhtml\System\Variable;

use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\View\Element\Template;
use Magento\Variable\Block\System\Variable\Edit as SystemVariableEdit;
use Magento\Variable\Controller\Adminhtml\System\Variable;
use Magento\Framework\App\Action\HttpGetActionInterface;

/**
* Display Variables edit form page
*
* @api
* @since 100.0.2
*/
class Edit extends \Magento\Variable\Controller\Adminhtml\System\Variable
class Edit extends Variable implements HttpGetActionInterface
{
/**
* Edit Action
*
* @return \Magento\Backend\Model\View\Result\Page
* @return Page
*/
public function execute()
{
Expand All @@ -29,10 +35,10 @@ public function execute()
$variable->getId() ? $variable->getCode() : __('New Custom Variable')
);
$resultPage->addContent($resultPage->getLayout()->createBlock(
\Magento\Variable\Block\System\Variable\Edit::class
SystemVariableEdit::class
))->addJs(
$resultPage->getLayout()->createBlock(
\Magento\Framework\View\Element\Template::class,
Template::class,
'',
['data' => ['template' => 'Magento_Variable::system/variable/js.phtml']]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
*/
namespace Magento\Variable\Controller\Adminhtml\System\Variable;

use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Variable\Controller\Adminhtml\System\Variable;

/**
* Display Variables list page
* @api
* @since 100.0.2
*/
class Index extends \Magento\Variable\Controller\Adminhtml\System\Variable implements HttpGetActionInterface
class Index extends Variable implements HttpGetActionInterface
{
/**
* Index Action
*
* @return \Magento\Backend\Model\View\Result\Page
* @return Page
*/
public function execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
*/
namespace Magento\Variable\Controller\Adminhtml\System\Variable;

use Magento\Backend\Model\View\Result\Forward;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Variable\Controller\Adminhtml\System\Variable;

/**
* Create new variable form
*
* @api
* @since 100.0.2
*/
class NewAction extends \Magento\Variable\Controller\Adminhtml\System\Variable
class NewAction extends Variable implements HttpGetActionInterface
{
/**
* New Action (forward to edit action)
*
* @return \Magento\Backend\Model\View\Result\Forward
* @return Forward
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
/** @var Forward $resultForward */
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('edit');
}
Expand Down
Loading