Skip to content

Commit 3041fc6

Browse files
author
larsroettig
committed
#30936: Code Review Fixes
1 parent 3819438 commit 3041fc6

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

app/code/Magento/Cms/Model/Page/DataProvider.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
2828
* @var array
2929
*/
3030
protected $loadedData;
31-
/** @var PageRepositoryInterface */
31+
32+
/**
33+
* @var PageRepositoryInterface
34+
*/
3235
private $pageRepository;
36+
3337
/**
3438
* @var AuthorizationInterface
3539
*/
@@ -44,6 +48,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
4448
* @var CustomLayoutManagerInterface
4549
*/
4650
private $customLayoutManager;
51+
4752
/**
4853
* @var null|array
4954
*/
@@ -111,8 +116,9 @@ public function getData(): array
111116
return $this->loadedData;
112117
}
113118

114-
$page = $this->getCurrentPage();
115-
if ($page === null) {
119+
try {
120+
$page = $this->getCurrentPage();
121+
} catch (LocalizedException $exception) {
116122
return [];
117123
}
118124

@@ -141,29 +147,26 @@ public function getData(): array
141147

142148
/**
143149
* Loads the current page by current request params.
144-
* @return Page|null
150+
* @return Page
151+
* @throws LocalizedException
145152
*/
146-
private function getCurrentPage(): ?Page
153+
private function getCurrentPage(): Page
147154
{
148155
if (!$this->getRequestFieldName()) {
149-
return null;
156+
throw new LocalizedException(__('RequestFieldName is not spefied'));
150157
}
151158

152159
$pageId = (int)$this->request->getParam($this->getRequestFieldName());
153160
if ($pageId === 0) {
154-
return null;
161+
throw new LocalizedException(__('Page size must be given'));
155162
}
156163

157164
if (isset($this->loadedPages[$pageId])) {
158165
return $this->loadedPages[$pageId];
159166
}
160167

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];
167170
}
168171

169172
/**
@@ -199,16 +202,19 @@ public function getMeta(): array
199202

200203
//List of custom layout files available for current page.
201204
$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();
205208
if ($page->getCustomLayoutUpdateXml() || $page->getLayoutUpdateXml()) {
206209
$options[] = ['label' => 'Use existing layout update XML', 'value' => '_existing_'];
207210
}
208211
foreach ($this->customLayoutManager->fetchAvailableFiles($page) as $layoutFile) {
209212
$options[] = ['label' => $layoutFile, 'value' => $layoutFile];
210213
}
214+
} catch (LocalizedException $exception) {
215+
211216
}
217+
212218
$customLayoutMeta = [
213219
'design' => [
214220
'children' => [

0 commit comments

Comments
 (0)