1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Variable\Controller\Adminhtml\System;
use Magento\Backend\App\Action;
/**
* Custom Variables admin controller
*/
abstract class Variable extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Variable::variable';
/**
* Core registry
*
* @var \Magento\Framework\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
*/
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
) {
$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
*/
protected function createPage()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Magento_Variable::system_variable')
->addBreadcrumb(__('Custom Variables'), __('Custom Variables'));
return $resultPage;
}
/**
* Initialize Variable object
*
* @return \Magento\Variable\Model\Variable
*/
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);
if ($variableId) {
$variable->setStoreId($storeId)->load($variableId);
}
$this->_coreRegistry->register('current_variable', $variable);
return $variable;
}
}