messageManager = $messageManager; $this->_page = $page; $this->_design = $design; $this->_pageFactory = $pageFactory; $this->_storeManager = $storeManager; $this->_localeDate = $localeDate; $this->_escaper = $escaper; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * Return result CMS page * * @param Action $action * @param int $pageId * @return \Magento\Framework\View\Result\Page|bool */ public function prepareResultPage(Action $action, $pageId = null) { if ($pageId !== null && $pageId !== $this->_page->getId()) { $delimiterPosition = strrpos($pageId, '|'); if ($delimiterPosition) { $pageId = substr($pageId, 0, $delimiterPosition); } $this->_page->setStoreId($this->_storeManager->getStore()->getId()); if (!$this->_page->load($pageId)) { return false; } } if (!$this->_page->getId()) { return false; } $inRange = $this->_localeDate->isScopeDateInInterval( null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo() ); if ($this->_page->getCustomTheme()) { if ($inRange) { $this->_design->setDesignTheme($this->_page->getCustomTheme()); } } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->setLayoutType($inRange, $resultPage); $resultPage->addHandle('cms_page_view'); $resultPage->addPageLayoutHandles(['id' => str_replace('/', '_', $this->_page->getIdentifier())]); $this->_eventManager->dispatch( 'cms_page_render', ['page' => $this->_page, 'controller_action' => $action, 'request' => $this->_getRequest()] ); if ($this->_page->getCustomLayoutUpdateXml() && $inRange) { $layoutUpdate = $this->_page->getCustomLayoutUpdateXml(); } else { $layoutUpdate = $this->_page->getLayoutUpdateXml(); } if (!empty($layoutUpdate)) { $resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate); } $contentHeadingBlock = $resultPage->getLayout()->getBlock('page_content_heading'); if ($contentHeadingBlock) { $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading()); $contentHeadingBlock->setContentHeading($contentHeading); } return $resultPage; } /** * Retrieve page direct URL * * @param string $pageId * @return string */ public function getPageUrl($pageId = null) { /** @var \Magento\Cms\Model\Page $page */ $page = $this->_pageFactory->create(); if ($pageId !== null && $pageId !== $page->getId()) { $page->setStoreId($this->_storeManager->getStore()->getId()); $page->load($pageId); } if (!$page->getId()) { return null; } return $this->_urlBuilder->getUrl(null, ['_direct' => $page->getIdentifier()]); } /** * Set layout type * * @param bool $inRange * @param \Magento\Framework\View\Result\Page $resultPage * @return \Magento\Framework\View\Result\Page */ protected function setLayoutType($inRange, $resultPage) { if ($this->_page->getPageLayout()) { if ($this->_page->getCustomPageLayout() && $this->_page->getCustomPageLayout() != 'empty' && $inRange ) { $handle = $this->_page->getCustomPageLayout(); } else { $handle = $this->_page->getPageLayout(); } $resultPage->getConfig()->setPageLayout($handle); } return $resultPage; } }