|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Firegento\DevDashboard\Plugin; |
|
5
|
|
|
|
|
6
|
|
|
use Magento\Framework\Controller\ResultFactory; |
|
7
|
|
|
use Magento\Framework\ObjectManager\ObjectManager; |
|
8
|
|
|
|
|
9
|
|
|
class SaveUserConfig |
|
10
|
|
|
{ |
|
11
|
|
|
protected $_configRepository; |
|
12
|
|
|
|
|
13
|
|
|
protected $_messageManager; |
|
14
|
|
|
|
|
15
|
|
|
protected $_session; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* SaveConfig constructor. |
|
19
|
|
|
* @param \Firegento\DevDashboard\Model\ConfigRepository $configRepository |
|
20
|
|
|
* @param \Magento\Framework\Message\ManagerInterface $messageManager |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
\Firegento\DevDashboard\Model\ConfigRepository $configRepository, |
|
24
|
|
|
\Magento\Framework\Message\ManagerInterface $messageManager, |
|
25
|
|
|
\Magento\Backend\Model\Auth\Session $session |
|
26
|
|
|
) { |
|
27
|
|
|
$this->_configRepository = $configRepository; |
|
28
|
|
|
$this->_messageManager = $messageManager; |
|
29
|
|
|
$this->_session = $session; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param \Magento\User\Controller\Adminhtml\User\Save $subject |
|
34
|
|
|
* @return array |
|
35
|
|
|
* @throws \Exception |
|
36
|
|
|
*/ |
|
37
|
|
|
public function afterExecute(\Magento\Backend\Controller\Adminhtml\System\Account\Save $subject, $result) |
|
38
|
|
|
{ |
|
39
|
|
|
$userId = $this->_session->getUser()->getId(); |
|
40
|
|
|
if ($userId === 0) { |
|
41
|
|
|
return []; |
|
42
|
|
|
} |
|
43
|
|
|
$data = (bool) $subject->getRequest()->getParam('use_devdashboard', false); |
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
|
|
/** @var \Firegento\DevDashboard\Model\Config $configModel */ |
|
47
|
|
|
$configModel = $this->_configRepository->getByUserId($userId); |
|
48
|
|
|
$configModel->setData('use_devdashboard', $data); |
|
49
|
|
|
$this->_configRepository->save($configModel); |
|
50
|
|
|
} catch (\Exception $e) { |
|
51
|
|
|
$this->_messageManager->addErrorMessage($e->getMessage()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $result; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|