Skip to content

Commit

Permalink
add logging, move operation from try block
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Dec 11, 2020
1 parent 17316ae commit 912374c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions app/code/Magento/Cms/Model/Page/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Ui\DataProvider\ModifierPoolDataProvider;
use Psr\Log\LoggerInterface;

/**
* Class DataProvider
* Cms Page DataProvider
*/
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
class DataProvider extends ModifierPoolDataProvider
{
/**
* @var DataPersistorInterface
Expand Down Expand Up @@ -55,6 +57,11 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
*/
private $loadedPages;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param string $name
* @param string $primaryFieldName
Expand All @@ -68,6 +75,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
* @param RequestInterface|null $request
* @param CustomLayoutManagerInterface|null $customLayoutManager
* @param PageRepositoryInterface|null $pageRepository
* @param LoggerInterface|null $logger
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -82,7 +90,8 @@ public function __construct(
?AuthorizationInterface $auth = null,
?RequestInterface $request = null,
?CustomLayoutManagerInterface $customLayoutManager = null,
?PageRepositoryInterface $pageRepository = null
?PageRepositoryInterface $pageRepository = null,
?LoggerInterface $logger = null
) {
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
$this->collection = $pageCollectionFactory->create();
Expand All @@ -93,6 +102,7 @@ public function __construct(
$this->customLayoutManager = $customLayoutManager
?? ObjectManager::getInstance()->get(CustomLayoutManagerInterface::class);
$this->pageRepository = $pageRepository ?? ObjectManager::getInstance()->get(PageRepositoryInterface::class);
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
}

/**
Expand Down Expand Up @@ -132,7 +142,7 @@ public function getData(): array

$data = $this->dataPersistor->get('cms_page');
if (empty($data)) {
return $this->loadedData;
return $this->loadedData;
}

$page = $this->collection->getNewEmptyItem();
Expand All @@ -148,6 +158,7 @@ public function getData(): array

/**
* Loads the current page by current request params.
*
* @return Page
* @throws LocalizedException
*/
Expand Down Expand Up @@ -204,16 +215,20 @@ public function getMeta(): array
//List of custom layout files available for current page.
$options = [['label' => 'No update', 'value' => '_no_update_']];

$page = null;
try {
$page = $this->getCurrentPage();
} catch (LocalizedException $e) {
$this->logger->error($e->getMessage());
}

if ($page) {
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 = [
Expand Down

0 comments on commit 912374c

Please sign in to comment.