Total Complexity | 5 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
5 | class SaveConfig |
||
6 | { |
||
7 | /** |
||
8 | * Form values from admin user save action, that are passed to the user specific config model |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $_whitelist =[ |
||
13 | 'user_id', |
||
14 | 'configuration', |
||
15 | 'use_devdashboard' |
||
16 | ]; |
||
17 | |||
18 | protected $_configRepository; |
||
19 | |||
20 | protected $_messageManager; |
||
21 | |||
22 | /** |
||
23 | * SaveConfig constructor. |
||
24 | * @param \Firegento\DevDashboard\Model\ConfigRepository $configRepository |
||
25 | * @param \Magento\Framework\Message\ManagerInterface $messageManager |
||
26 | */ |
||
27 | public function __construct( |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param \Magento\User\Controller\Adminhtml\User\Save $subject |
||
37 | * @return array |
||
38 | * @throws \Exception |
||
39 | */ |
||
40 | public function afterExecute(\Magento\User\Controller\Adminhtml\User\Save $subject) |
||
41 | { |
||
42 | $userId = (int)$subject->getRequest()->getParam('user_id'); |
||
43 | if ($userId === 0) { |
||
44 | return []; |
||
45 | } |
||
46 | $data = $this->_filterData($subject->getRequest()->getParams()); |
||
47 | |||
48 | try { |
||
49 | |||
50 | /** @var \Firegento\DevDashboard\Model\Config $model */ |
||
51 | $model = $this->_configRepository->getByUserId($userId); |
||
52 | $model->setData($data); |
||
53 | $this->_configRepository->save($model); |
||
54 | } catch (\Exception $e) { |
||
55 | $this->_messageManager->addErrorMessage($e->getMessage()); |
||
56 | } |
||
57 | return []; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param $data |
||
62 | * @return array |
||
63 | */ |
||
64 | protected function _filterData($data) |
||
67 | } |
||
68 | } |
||
69 |