11
11
use Magento \Framework \App \ObjectManager ;
12
12
use Magento \Framework \App \Request \DataPersistorInterface ;
13
13
use Magento \Framework \App \RequestInterface ;
14
+ use Magento \Framework \AuthorizationInterface ;
14
15
use Magento \Framework \Exception \LocalizedException ;
15
16
use Magento \Ui \DataProvider \Modifier \PoolInterface ;
16
- use Magento \Framework \AuthorizationInterface ;
17
+ use Magento \Ui \DataProvider \ModifierPoolDataProvider ;
18
+ use Psr \Log \LoggerInterface ;
17
19
18
20
/**
19
- * Class DataProvider
21
+ * Cms Page DataProvider
20
22
*/
21
- class DataProvider extends \ Magento \ Ui \ DataProvider \ ModifierPoolDataProvider
23
+ class DataProvider extends ModifierPoolDataProvider
22
24
{
23
25
/**
24
26
* @var DataPersistorInterface
@@ -55,6 +57,11 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
55
57
*/
56
58
private $ loadedPages ;
57
59
60
+ /**
61
+ * @var LoggerInterface
62
+ */
63
+ private $ logger ;
64
+
58
65
/**
59
66
* @param string $name
60
67
* @param string $primaryFieldName
@@ -68,6 +75,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
68
75
* @param RequestInterface|null $request
69
76
* @param CustomLayoutManagerInterface|null $customLayoutManager
70
77
* @param PageRepositoryInterface|null $pageRepository
78
+ * @param LoggerInterface|null $logger
71
79
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
72
80
*/
73
81
public function __construct (
@@ -82,7 +90,8 @@ public function __construct(
82
90
?AuthorizationInterface $ auth = null ,
83
91
?RequestInterface $ request = null ,
84
92
?CustomLayoutManagerInterface $ customLayoutManager = null ,
85
- ?PageRepositoryInterface $ pageRepository = null
93
+ ?PageRepositoryInterface $ pageRepository = null ,
94
+ ?LoggerInterface $ logger = null
86
95
) {
87
96
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
88
97
$ this ->collection = $ pageCollectionFactory ->create ();
@@ -93,6 +102,7 @@ public function __construct(
93
102
$ this ->customLayoutManager = $ customLayoutManager
94
103
?? ObjectManager::getInstance ()->get (CustomLayoutManagerInterface::class);
95
104
$ this ->pageRepository = $ pageRepository ?? ObjectManager::getInstance ()->get (PageRepositoryInterface::class);
105
+ $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
96
106
}
97
107
98
108
/**
@@ -132,7 +142,7 @@ public function getData(): array
132
142
133
143
$ data = $ this ->dataPersistor ->get ('cms_page ' );
134
144
if (empty ($ data )) {
135
- return $ this ->loadedData ;
145
+ return $ this ->loadedData ;
136
146
}
137
147
138
148
$ page = $ this ->collection ->getNewEmptyItem ();
@@ -148,6 +158,7 @@ public function getData(): array
148
158
149
159
/**
150
160
* Loads the current page by current request params.
161
+ *
151
162
* @return Page
152
163
* @throws LocalizedException
153
164
*/
@@ -204,16 +215,20 @@ public function getMeta(): array
204
215
//List of custom layout files available for current page.
205
216
$ options = [['label ' => 'No update ' , 'value ' => '_no_update_ ' ]];
206
217
218
+ $ page = null ;
207
219
try {
208
220
$ page = $ this ->getCurrentPage ();
221
+ } catch (LocalizedException $ e ) {
222
+ $ this ->logger ->error ($ e ->getMessage ());
223
+ }
224
+
225
+ if ($ page ) {
209
226
if ($ page ->getCustomLayoutUpdateXml () || $ page ->getLayoutUpdateXml ()) {
210
227
$ options [] = ['label ' => 'Use existing layout update XML ' , 'value ' => '_existing_ ' ];
211
228
}
212
229
foreach ($ this ->customLayoutManager ->fetchAvailableFiles ($ page ) as $ layoutFile ) {
213
230
$ options [] = ['label ' => $ layoutFile , 'value ' => $ layoutFile ];
214
231
}
215
- } catch (LocalizedException $ exception ) {
216
-
217
232
}
218
233
219
234
$ customLayoutMeta = [
0 commit comments