Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractConfig.php
Go to the documentation of this file.
1 <?php
8 
10 
17 {
23  const ADMIN_RESOURCE = 'Magento_Config::config';
24 
28  protected $_configStructure;
29 
33  protected $_sectionChecker;
34 
40  public function __construct(
41  \Magento\Backend\App\Action\Context $context,
42  \Magento\Config\Model\Config\Structure $configStructure,
43  $sectionChecker
44  ) {
45  parent::__construct($context);
46  $this->_configStructure = $configStructure;
47  $this->_sectionChecker = $sectionChecker;
48  }
49 
56  public function dispatch(\Magento\Framework\App\RequestInterface $request)
57  {
58  if (!$request->getParam('section')) {
59  try {
60  $request->setParam('section', $this->_configStructure->getFirstSection()->getId());
61  } catch (LocalizedException $e) {
63  $this->messageManager->addWarningMessage($e->getMessage());
64  }
65  }
66  return parent::dispatch($request);
67  }
68 
74  protected function _isAllowed()
75  {
76  $sectionId = $this->_request->getParam('section');
77  return parent::_isAllowed()
78  || $this->_configStructure->getElement($sectionId)->isAllowed();
79  }
80 
87  protected function _saveState($configState = [])
88  {
89  if (is_array($configState)) {
90  $configState = $this->sanitizeConfigState($configState);
91  $adminUser = $this->_auth->getUser();
92  $extra = $adminUser->getExtra();
93  if (!is_array($extra)) {
94  $extra = [];
95  }
96  if (!isset($extra['configState'])) {
97  $extra['configState'] = [];
98  }
99  foreach ($configState as $fieldset => $state) {
100  $extra['configState'][$fieldset] = $state;
101  }
102  $adminUser->saveExtra($extra);
103  }
104  return true;
105  }
106 
115  protected function sanitizeConfigState($configState)
116  {
117  $sectionList = $this->_configStructure->getSectionList();
118  $sanitizedConfigState = $configState;
119  foreach ($configState as $sectionId => $value) {
120  if (array_key_exists($sectionId, $sectionList)) {
121  $sanitizedConfigState[$sectionId] = (bool)$sanitizedConfigState[$sectionId] ? '1' : '0';
122  } else {
123  unset($sanitizedConfigState[$sectionId]);
124  }
125  }
126  return $sanitizedConfigState;
127  }
128 }
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Config\Model\Config\Structure $configStructure, $sectionChecker)
$value
Definition: gender.phtml:16
dispatch(\Magento\Framework\App\RequestInterface $request)
if( $_orders &&count( $_orders))( 'Orders') ?></caption >< thead >< tr >< th scopeforeach( $_orders as $_order)(__( 'Order #')) ?>" class $extra
Definition: history.phtml:32