@@ -28,8 +28,12 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
28
28
* @var array
29
29
*/
30
30
protected $ loadedData ;
31
- /** @var PageRepositoryInterface */
31
+
32
+ /**
33
+ * @var PageRepositoryInterface
34
+ */
32
35
private $ pageRepository ;
36
+
33
37
/**
34
38
* @var AuthorizationInterface
35
39
*/
@@ -44,6 +48,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
44
48
* @var CustomLayoutManagerInterface
45
49
*/
46
50
private $ customLayoutManager ;
51
+
47
52
/**
48
53
* @var null|array
49
54
*/
@@ -111,8 +116,9 @@ public function getData(): array
111
116
return $ this ->loadedData ;
112
117
}
113
118
114
- $ page = $ this ->getCurrentPage ();
115
- if ($ page === null ) {
119
+ try {
120
+ $ page = $ this ->getCurrentPage ();
121
+ } catch (LocalizedException $ exception ) {
116
122
return [];
117
123
}
118
124
@@ -141,29 +147,26 @@ public function getData(): array
141
147
142
148
/**
143
149
* Loads the current page by current request params.
144
- * @return Page|null
150
+ * @return Page
151
+ * @throws LocalizedException
145
152
*/
146
- private function getCurrentPage (): ? Page
153
+ private function getCurrentPage (): Page
147
154
{
148
155
if (!$ this ->getRequestFieldName ()) {
149
- return null ;
156
+ throw new LocalizedException ( __ ( ' RequestFieldName is not spefied ' )) ;
150
157
}
151
158
152
159
$ pageId = (int )$ this ->request ->getParam ($ this ->getRequestFieldName ());
153
160
if ($ pageId === 0 ) {
154
- return null ;
161
+ throw new LocalizedException ( __ ( ' Page size must be given ' )) ;
155
162
}
156
163
157
164
if (isset ($ this ->loadedPages [$ pageId ])) {
158
165
return $ this ->loadedPages [$ pageId ];
159
166
}
160
167
161
- try {
162
- $ this ->loadedPages [$ pageId ] = $ this ->pageRepository ->getById ($ pageId );
163
- return $ this ->loadedPages [$ pageId ];
164
- } catch (LocalizedException $ exception ) {
165
- return null ;
166
- }
168
+ $ this ->loadedPages [$ pageId ] = $ this ->pageRepository ->getById ($ pageId );
169
+ return $ this ->loadedPages [$ pageId ];
167
170
}
168
171
169
172
/**
@@ -199,16 +202,19 @@ public function getMeta(): array
199
202
200
203
//List of custom layout files available for current page.
201
204
$ options = [['label ' => 'No update ' , 'value ' => '_no_update_ ' ]];
202
- if ( $ page = $ this -> getCurrentPage ()) {
203
- //We must have a specific page selected.
204
- //If custom layout XML is set then displaying this special option.
205
+
206
+ try {
207
+ $ page = $ this -> getCurrentPage ();
205
208
if ($ page ->getCustomLayoutUpdateXml () || $ page ->getLayoutUpdateXml ()) {
206
209
$ options [] = ['label ' => 'Use existing layout update XML ' , 'value ' => '_existing_ ' ];
207
210
}
208
211
foreach ($ this ->customLayoutManager ->fetchAvailableFiles ($ page ) as $ layoutFile ) {
209
212
$ options [] = ['label ' => $ layoutFile , 'value ' => $ layoutFile ];
210
213
}
214
+ } catch (LocalizedException $ exception ) {
215
+
211
216
}
217
+
212
218
$ customLayoutMeta = [
213
219
'design ' => [
214
220
'children ' => [
0 commit comments