Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
13 
14 use \Magento\Framework\App\ObjectManager;
15 use \Magento\Framework\Serialize\Serializer\Json;
16 
23 {
24  const DEFAULT_SECTION_BLOCK = \Magento\Config\Block\System\Config\Form::class;
25 
31  protected $_formBlockName;
32 
38  protected $_template = 'Magento_Config::system/config/edit.phtml';
39 
45  protected $_configStructure;
46 
50  private $jsonSerializer;
51 
58  public function __construct(
59  \Magento\Backend\Block\Template\Context $context,
60  \Magento\Config\Model\Config\Structure $configStructure,
61  array $data = [],
62  Json $jsonSerializer = null
63  ) {
64  $this->_configStructure = $configStructure;
65  $this->jsonSerializer = $jsonSerializer ?: ObjectManager::getInstance()->get(Json::class);
66  parent::__construct($context, $data);
67  }
68 
74  protected function _prepareLayout()
75  {
77  $section = $this->_configStructure->getElement($this->getRequest()->getParam('section'));
78  $this->_formBlockName = $section->getFrontendModel();
79  if (empty($this->_formBlockName)) {
80  $this->_formBlockName = self::DEFAULT_SECTION_BLOCK;
81  }
82  $this->setTitle($section->getLabel());
83  $this->setHeaderCss($section->getHeaderCss());
84 
85  $this->getToolbar()->addChild(
86  'save_button',
87  \Magento\Backend\Block\Widget\Button::class,
88  [
89  'id' => 'save',
90  'label' => __('Save Config'),
91  'class' => 'save primary',
92  'data_attribute' => [
93  'mage-init' => ['button' => ['event' => 'save', 'target' => '#config-edit-form']],
94  ]
95  ]
96  );
97  $block = $this->getLayout()->createBlock($this->_formBlockName);
98  $this->setChild('form', $block);
99  return parent::_prepareLayout();
100  }
101 
107  public function getSaveButtonHtml()
108  {
109  return $this->getChildHtml('save_button');
110  }
111 
117  public function getSaveUrl()
118  {
119  return $this->getUrl('*/system_config/save', ['_current' => true]);
120  }
121 
125  public function getConfigSearchParamsJson()
126  {
127  $params = [];
128  if ($this->getRequest()->getParam('section')) {
129  $params['section'] = $this->getRequest()->getParam('section');
130  }
131  if ($this->getRequest()->getParam('group')) {
132  $params['group'] = $this->getRequest()->getParam('group');
133  }
134  if ($this->getRequest()->getParam('field')) {
135  $params['field'] = $this->getRequest()->getParam('field');
136  }
137  return $this->jsonSerializer->serialize($params);
138  }
139 }
__()
Definition: __.php:13
$block
Definition: block.php:8
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Config\Model\Config\Structure $configStructure, array $data=[], Json $jsonSerializer=null)
Definition: Edit.php:58
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18