![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Block/Adminhtml/Configuration/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Block\Adminhtml\Configuration; use Extmag\Shiplab\Helper\Config; use Magento\Backend\Block\Template\Context; use Magento\Backend\Block\Widget; use Magento\Backend\Block\Widget\Button; use Magento\Config\Model\Config\Structure; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\View\Element\AbstractBlock; class Edit extends Widget { const DEFAULT_SECTION_BLOCK = Form::class; /** * Form block class name * * @var string */ protected $_formBlockName; /** * Block template File * * @var string */ protected $_template = 'Extmag_Shiplab::configuration/edit.phtml'; /** * Configuration structure * * @var Structure */ protected $_configStructure; /** * @var Json */ protected $jsonSerializer; /** * @param Context $context * @param Config $configStructure * @param array $data * @param Json|null $jsonSerializer */ public function __construct( Context $context, Config $configStructure, Json $jsonSerializer, array $data = [] ) { parent::__construct($context, $data); $this->_configStructure = $configStructure; $this->jsonSerializer = $jsonSerializer; } /** * Retrieve rendered save buttons * * @return string */ public function getSaveButtonHtml() { return $this->getChildHtml('save_button'); } /** * Retrieve config save url * * @return string */ public function getSaveUrl() { return $this->getUrl('*/configuration/save', ['_current' => true]); } /** * @return string */ public function getConfigSearchParamsJson() { $params = []; if ($this->getRequest()->getParam('section')) { $params['section'] = $this->getRequest()->getParam('section'); } if ($this->getRequest()->getParam('group')) { $params['group'] = $this->getRequest()->getParam('group'); } if ($this->getRequest()->getParam('field')) { $params['field'] = $this->getRequest()->getParam('field'); } return $this->jsonSerializer->serialize($params); } /** * Prepare layout object * * @return AbstractBlock * @throws LocalizedException */ protected function _prepareLayout() { $section = $this->_configStructure->getElement($this->getRequest()->getParam('section')); $this->_formBlockName = $section->getFrontendModel(); if (empty($this->_formBlockName)) { $this->_formBlockName = self::DEFAULT_SECTION_BLOCK; } $this->setTitle($section->getLabel()); $this->setHeaderCss($section->getHeaderCss()); $this->getToolbar()->addChild( 'save_button', Button::class, [ 'id' => 'save', 'label' => __('Save Config'), 'class' => 'save primary', 'data_attribute' => [ 'mage-init' => ['button' => ['event' => 'save', 'target' => '#config-edit-form']], ], ] ); $block = $this->getLayout()->createBlock($this->_formBlockName); $this->setChild('form', $block); return $this; } }