Skip to content

Commit

Permalink
#30936: Code Review Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
larsroettig committed Dec 3, 2020
1 parent 3819438 commit 3041fc6
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions app/code/Magento/Cms/Model/Page/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
* @var array
*/
protected $loadedData;
/** @var PageRepositoryInterface */

/**
* @var PageRepositoryInterface
*/
private $pageRepository;

/**
* @var AuthorizationInterface
*/
Expand All @@ -44,6 +48,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
* @var CustomLayoutManagerInterface
*/
private $customLayoutManager;

/**
* @var null|array
*/
Expand Down Expand Up @@ -111,8 +116,9 @@ public function getData(): array
return $this->loadedData;
}

$page = $this->getCurrentPage();
if ($page === null) {
try {
$page = $this->getCurrentPage();
} catch (LocalizedException $exception) {
return [];
}

Expand Down Expand Up @@ -141,29 +147,26 @@ public function getData(): array

/**
* Loads the current page by current request params.
* @return Page|null
* @return Page
* @throws LocalizedException
*/
private function getCurrentPage(): ?Page
private function getCurrentPage(): Page
{
if (!$this->getRequestFieldName()) {
return null;
throw new LocalizedException(__('RequestFieldName is not spefied'));
}

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

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

try {
$this->loadedPages[$pageId] = $this->pageRepository->getById($pageId);
return $this->loadedPages[$pageId];
} catch (LocalizedException $exception) {
return null;
}
$this->loadedPages[$pageId] = $this->pageRepository->getById($pageId);
return $this->loadedPages[$pageId];
}

/**
Expand Down Expand Up @@ -199,16 +202,19 @@ public function getMeta(): array

//List of custom layout files available for current page.
$options = [['label' => 'No update', 'value' => '_no_update_']];
if ($page = $this->getCurrentPage()) {
//We must have a specific page selected.
//If custom layout XML is set then displaying this special option.

try {
$page = $this->getCurrentPage();
if ($page->getCustomLayoutUpdateXml() || $page->getLayoutUpdateXml()) {
$options[] = ['label' => 'Use existing layout update XML', 'value' => '_existing_'];
}
foreach ($this->customLayoutManager->fetchAvailableFiles($page) as $layoutFile) {
$options[] = ['label' => $layoutFile, 'value' => $layoutFile];
}
} catch (LocalizedException $exception) {

}

$customLayoutMeta = [
'design' => [
'children' => [
Expand Down

0 comments on commit 3041fc6

Please sign in to comment.