Skip to content

Commit 702d728

Browse files
author
Evgeniy Miskov
committed
Merge remote-tracking branch 'tango/MAGETWO-31524' into MAGETWO-31524
2 parents f36eac2 + 6798898 commit 702d728

File tree

5 files changed

+96
-14
lines changed

5 files changed

+96
-14
lines changed

app/code/Magento/Cms/Controller/Index/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function execute($coreRoute = null)
4040
\Magento\Cms\Helper\Page::XML_PATH_HOME_PAGE,
4141
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4242
);
43-
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
43+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->prepareResultPage($this, $pageId);
4444
if (!$resultPage) {
4545
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
4646
$resultForward = $this->resultForwardFactory->create();

app/code/Magento/Cms/Controller/Index/NoCookies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function execute()
3939
\Magento\Cms\Helper\Page::XML_PATH_NO_COOKIES_PAGE,
4040
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4141
);
42-
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
42+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->prepareResultPage($this, $pageId);
4343
if (!$resultPage) {
4444
$resultForward = $this->resultForwardFactory->create();
4545
return $resultForward->forward('defaultNoCookies');

app/code/Magento/Cms/Controller/Noroute/Index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
/**
2929
* Render CMS 404 Not found page
3030
*
31-
* @return \Magento\Backend\Model\View\Result\Forward
31+
* @return \Magento\Framework\Controller\ResultInterface
3232
*/
3333
public function execute()
3434
{
@@ -46,10 +46,12 @@ public function execute()
4646
);
4747
/** @var \Magento\Cms\Helper\Page $pageHelper */
4848
$pageHelper = $this->_objectManager->get('Magento\Cms\Helper\Page');
49-
if (!$pageHelper->renderPage($this, $pageId)) {
49+
$resultPage = $pageHelper->prepareResultPage($this, $pageId);
50+
if (!$resultPage) {
5051
$resultForward->setController('index');
5152
$resultForward->forward('defaultNoRoute');
5253
return $resultForward;
5354
}
55+
return $resultPage;
5456
}
5557
}

app/code/Magento/Cms/Controller/Page/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
public function execute()
3434
{
3535
$pageId = $this->getRequest()->getParam('page_id', $this->getRequest()->getParam('id', false));
36-
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
36+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->prepareResultPage($this, $pageId);
3737
if (!$resultPage) {
3838
$resultForward = $this->resultForwardFactory->create();
3939
return $resultForward->forward('noroute');

app/code/Magento/Cms/Helper/Page.php

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,95 @@ public function __construct(
129129
parent::__construct($context);
130130
}
131131

132+
/**
133+
* Return result CMS page
134+
*
135+
* @param Action $action
136+
* @param null $pageId
137+
* @return \Magento\Framework\View\Result\Page|bool
138+
*/
139+
public function prepareResultPage(Action $action, $pageId = null)
140+
{
141+
if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
142+
$delimiterPosition = strrpos($pageId, '|');
143+
if ($delimiterPosition) {
144+
$pageId = substr($pageId, 0, $delimiterPosition);
145+
}
146+
147+
$this->_page->setStoreId($this->_storeManager->getStore()->getId());
148+
if (!$this->_page->load($pageId)) {
149+
return false;
150+
}
151+
}
152+
153+
if (!$this->_page->getId()) {
154+
return false;
155+
}
156+
157+
$inRange = $this->_localeDate->isScopeDateInInterval(
158+
null,
159+
$this->_page->getCustomThemeFrom(),
160+
$this->_page->getCustomThemeTo()
161+
);
162+
163+
if ($this->_page->getCustomTheme()) {
164+
if ($inRange) {
165+
$this->_design->setDesignTheme($this->_page->getCustomTheme());
166+
}
167+
}
168+
/** @var \Magento\Framework\View\Result\Page $resultPage */
169+
$resultPage = $this->resultPageFactory->create();
170+
if ($this->_page->getPageLayout()) {
171+
if ($this->_page->getCustomPageLayout()
172+
&& $this->_page->getCustomPageLayout() != 'empty'
173+
&& $inRange
174+
) {
175+
$handle = $this->_page->getCustomPageLayout();
176+
} else {
177+
$handle = $this->_page->getPageLayout();
178+
}
179+
$resultPage->getConfig()->setPageLayout($handle);
180+
}
181+
$resultPage->initLayout();
182+
$resultPage->addHandle('cms_page_view');
183+
$resultPage->addPageLayoutHandles(['id' => $this->_page->getIdentifier()]);
184+
185+
$this->_eventManager->dispatch(
186+
'cms_page_render',
187+
['page' => $this->_page, 'controller_action' => $action]
188+
);
189+
190+
if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
191+
$layoutUpdate = $this->_page->getCustomLayoutUpdateXml();
192+
} else {
193+
$layoutUpdate = $this->_page->getLayoutUpdateXml();
194+
}
195+
if (!empty($layoutUpdate)) {
196+
$resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate);
197+
}
198+
199+
$contentHeadingBlock = $resultPage->getLayout()->getBlock('page_content_heading');
200+
if ($contentHeadingBlock) {
201+
$contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading());
202+
$contentHeadingBlock->setContentHeading($contentHeading);
203+
}
204+
205+
/* @TODO: Move catalog and checkout storage types to appropriate modules */
206+
$messageBlock = $resultPage->getLayout()->getMessagesBlock();
207+
$messageBlock->addStorageType($this->messageManager->getDefaultGroup());
208+
$messageBlock->addMessages($this->messageManager->getMessages(true));
209+
210+
return $resultPage;
211+
}
212+
132213
/**
133214
* Renders CMS page on front end
134215
*
135216
* Call from controller action
136217
*
137218
* @param Action $action
138219
* @param int $pageId
139-
* @return bool|\Magento\Framework\View\Result\Page
220+
* @return bool
140221
*/
141222
public function renderPage(Action $action, $pageId = null)
142223
{
@@ -148,12 +229,12 @@ public function renderPage(Action $action, $pageId = null)
148229
*
149230
* @param Action $action
150231
* @param int $pageId
151-
* @param bool $returnPage
152-
* @return bool|\Magento\Framework\View\Result\Page
232+
* @param bool $renderLayout
233+
* @return bool
153234
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
154235
* @SuppressWarnings(PHPMD.NPathComplexity)
155236
*/
156-
protected function _renderPage(Action $action, $pageId = null, $returnPage = true)
237+
protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
157238
{
158239
if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
159240
$delimiterPosition = strrpos($pageId, '|');
@@ -182,8 +263,7 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
182263
$this->_design->setDesignTheme($this->_page->getCustomTheme());
183264
}
184265
}
185-
/** @var \Magento\Framework\View\Result\Page $resultPage */
186-
$resultPage = $this->resultPageFactory->create();
266+
$resultPage = $this->_view->getPage();
187267
if ($this->_page->getPageLayout()) {
188268
if ($this->_page->getCustomPageLayout()
189269
&& $this->_page->getCustomPageLayout() != 'empty'
@@ -224,8 +304,8 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
224304
$messageBlock->addStorageType($this->messageManager->getDefaultGroup());
225305
$messageBlock->addMessages($this->messageManager->getMessages(true));
226306

227-
if ($returnPage) {
228-
return $resultPage;
307+
if ($renderLayout) {
308+
$this->_view->renderLayout();
229309
}
230310

231311
return true;
@@ -239,7 +319,7 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
239319
* @param Action $action
240320
* @param int $pageId
241321
* @param bool $renderLayout
242-
* @return bool|\Magento\Framework\View\Result\Page
322+
* @return bool
243323
*/
244324
public function renderPageExtended(Action $action, $pageId = null, $renderLayout = true)
245325
{

0 commit comments

Comments
 (0)