forked from mageplaza/magento-2-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.php
168 lines (152 loc) · 4.14 KB
/
Store.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Webhook
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Webhook\Ui\Component\Listing\Columns;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Store\Model\StoreManagerInterface as StoreManager;
use Magento\Store\Model\System\Store as SystemStore;
use Magento\Ui\Component\Listing\Columns\Column;
/**
* Class Store
* @package Mageplaza\Webhook\Ui\Component\Listing\Columns
*/
class Store extends Column
{
/**
* Escaper
*
* @var Escaper
*/
protected $escaper;
/**
* System store
*
* @var SystemStore
*/
protected $systemStore;
/**
* Store manager
*
* @var StoreManager
*/
protected $storeManager;
/**
* @var string
*/
protected $storeKey;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param SystemStore $systemStore
* @param Escaper $escaper
* @param array $components
* @param array $data
* @param string $storeKey
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
SystemStore $systemStore,
Escaper $escaper,
array $components = [],
array $data = [],
$storeKey = 'store_ids'
) {
$this->systemStore = $systemStore;
$this->escaper = $escaper;
$this->storeKey = $storeKey;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
*
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$item[$this->getData('name')] = $this->prepareItem($item);
}
}
return $dataSource;
}
/**
* Get data
*
* @param array $item
*
* @return string
*/
protected function prepareItem(array $item)
{
$content = '';
$origStores = explode(',', $item[$this->storeKey]);
if (!is_array($origStores)) {
$origStores = [$origStores];
}
if (in_array(0, $origStores)) {
return __('All Store Views');
}
$data = $this->systemStore->getStoresStructure(false, $origStores);
foreach ($data as $website) {
$content .= "<b>" . $website['label'] . "</b><br/>";
foreach ($website['children'] as $group) {
$content .= str_repeat(' ', 3) . "<b>" . $this->escaper->escapeHtml($group['label']) . "</b><br/>";
foreach ($group['children'] as $store) {
$content .= str_repeat(' ', 6) . $this->escaper->escapeHtml($store['label']) . "<br/>";
}
}
}
return $content;
}
/**
* Prepare component configuration
*
* @return void
*/
public function prepare()
{
parent::prepare();
if ($this->getStoreManager()->isSingleStoreMode()) {
$this->_data['config']['componentDisabled'] = true;
}
}
/**
* Get StoreManager dependency
*
* @return StoreManager
*
* @deprecated
*/
private function getStoreManager()
{
if ($this->storeManager === null) {
$this->storeManager = ObjectManager::getInstance()
->get(StoreManager::class);
}
return $this->storeManager;
}
}