Variable.php 3.2 KB

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