forked from mage-os/mageos-magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataProvider.php
More file actions
162 lines (149 loc) · 4.49 KB
/
DataProvider.php
File metadata and controls
162 lines (149 loc) · 4.49 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Ui\Component;
use Magento\Cms\Api\Data\PageInterface;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;
use Magento\Ui\Component\Container;
/**
* DataProvider for cms ui.
*/
class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
{
/**
* @var AuthorizationInterface
*/
private $authorization;
/**
* @var AddFilterInterface[]
*/
private $additionalFilterPool;
/**
* @var array
*/
private array $pageLayoutColumns = [
PageInterface::PAGE_LAYOUT,
PageInterface::CUSTOM_THEME,
PageInterface::CUSTOM_THEME_FROM,
PageInterface::CUSTOM_THEME_TO,
PageInterface::CUSTOM_ROOT_TEMPLATE
];
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param Reporting $reporting
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param RequestInterface $request
* @param FilterBuilder $filterBuilder
* @param array $meta
* @param array $data
* @param array $additionalFilterPool
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
Reporting $reporting,
SearchCriteriaBuilder $searchCriteriaBuilder,
RequestInterface $request,
FilterBuilder $filterBuilder,
array $meta = [],
array $data = [],
array $additionalFilterPool = []
) {
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$reporting,
$searchCriteriaBuilder,
$request,
$filterBuilder,
$meta,
$data
);
$this->meta = array_replace_recursive($meta, $this->prepareMetadata());
$this->additionalFilterPool = $additionalFilterPool;
}
/**
* Get authorization info.
*
* @deprecated 101.0.7
* @see nothing
*
* @return AuthorizationInterface|mixed
*/
private function getAuthorizationInstance()
{
if ($this->authorization === null) {
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
}
return $this->authorization;
}
/**
* Prepares Meta
*
* @return array
*/
public function prepareMetadata()
{
$metadata = [];
if (!$this->getAuthorizationInstance()->isAllowed('Magento_Cms::save')) {
$metadata = [
'cms_page_columns' => [
'arguments' => [
'data' => [
'config' => [
'editorConfig' => [
'enabled' => false
],
'componentType' => Container::NAME
]
]
]
]
];
}
if (!$this->getAuthorizationInstance()->isAllowed('Magento_Cms::save_design')) {
foreach ($this->pageLayoutColumns as $column) {
$metadata['cms_page_columns']['children'][$column] = [
'arguments' => [
'data' => [
'config' => [
'editor' => [
'editorType' => false
],
'componentType' => Container::NAME
]
]
]
];
}
}
return $metadata;
}
/**
* Add Filter
*
* @param Filter $filter
* @return void
*/
public function addFilter(Filter $filter): void
{
if (!empty($this->additionalFilterPool[$filter->getField()])) {
$this->additionalFilterPool[$filter->getField()]->addFilter($this->searchCriteriaBuilder, $filter);
} else {
parent::addFilter($filter);
}
}
}