-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathConfigObserver.php
More file actions
142 lines (127 loc) · 4.51 KB
/
ConfigObserver.php
File metadata and controls
142 lines (127 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/
namespace Magefan\Community\Observer;
use Magefan\Community\Model\SystemConfigAutoKeyManager;
use Magento\Framework\Event\ObserverInterface;
use Magefan\Community\Model\SectionFactory;
use Magefan\Community\Model\Section\Info;
use Magento\Framework\Message\ManagerInterface;
use Magefan\Community\Model\SetLinvFlag;
use Magefan\Community\Model\Config;
use Magefan\Community\Model\Section;
/**
* Community observer
*/
class ConfigObserver implements ObserverInterface
{
/**
* @var SectionFactory
*/
private $sectionFactory;
/**
* @var Info
*/
private $info;
/**
* @var ManagerInterface
*/
private $messageManager;
/**
* @var SetLinvFlag
*/
private $setLinvFlag;
/**
* @var Config
*/
private $config;
/**
* @var SystemConfigAutoKeyManager
*/
private $autoKeyManager;
/**
* ConfigObserver constructor.
* @param SectionFactory $sectionFactory
* @param Info $info
* @param ManagerInterface $messageManager
* @param SetLinvFlag $setLinvFlag
* @param Config $config
* @param SystemConfigAutoKeyManager $autoKeyManager
*/
final public function __construct(
SectionFactory $sectionFactory,
Info $info,
ManagerInterface $messageManager,
SetLinvFlag $setLinvFlag,
Config $config,
SystemConfigAutoKeyManager $autoKeyManager
) {
$this->sectionFactory = $sectionFactory;
$this->info = $info;
$this->messageManager = $messageManager;
$this->setLinvFlag = $setLinvFlag;
$this->config = $config;
$this->autoKeyManager = $autoKeyManager;
}
/**
* @param \Magento\Framework\Event\Observer $observer
*/
final public function execute(\Magento\Framework\Event\Observer $observer)
{
$request = $observer->getEvent()->getRequest();
$groups = $request->getParam('groups');
if (empty($groups['general']['fields']['enabled']['value'])) {
return;
}
$key = isset($groups['general']['fields']['key']['value'])
? $groups['general']['fields']['key']['value']
: null;
$section = $this->sectionFactory->create([
'name' => $request->getParam('section'),
'key' => $key
]);
if (!$section->getModule()) {
$bp = $section->getName() . '/' . 'g' . 'e' . 'n' . 'e' . 'r' . 'a' . 'l' . '/' ;
if (!$this->config->getConfig( $bp . Section::ACTIVE) && !$section->getType()) {
$this->messageManager->addError(
implode(array_reverse(
[
'.','e','g','a','s','u',' ','e','e','r','f',' ','y','o','j','n','e',' ',
'o','t',' ','t','i',' ','e','t','a','v','i','t','c','a',' ','e','s','a',
'e','l','P',' ','.','d','e','t','a','v','i','t','c','a',' ','t','o','n',
' ','s','i',' ','n','o','i','s','n','e','t','x','e',' ','e','h','T'
]
))
);
$groups['general']['fields']['enabled']['value'] = 0;
$request->setPostValue('groups', $groups);
}
return;
}
$module = $section->getName();
$data = $this->info->load([$section]);
if (!$section->validate($data)) {
$groups['general']['fields']['enabled']['value'] = 0;
$this->setLinvFlag->execute($module, 1);
$request->setPostValue('groups', $groups);
$this->messageManager->addError(
implode(array_reverse(
[
'.','d','e','l','b','a','s','i','d',' ','y','l','l','a','c','i','t','a','m',
'o','t','u','a',' ','n','e','e','b',' ','s','a','h',' ','n','o','i','s','n',
'e','t','x','e',' ','e','h','T',' ','.','d','i','l','a','v','n','i',' ','r',
'o',' ','y','t','p','m','e',' ','s','i',' ','y','e','K',' ','t','c','u','d',
'o','r','P'
]
))
);
} else {
$this->setLinvFlag->execute($module, 0);
if ($key) {
$this->autoKeyManager->execute($section->getName(),$key);
}
}
}
}