Skip to content

Commit bce58ca

Browse files
author
vpaladiychuk
committed
MAGETWO-31524: Refactor controller actions in the CMS module
1 parent 084fc7a commit bce58ca

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
/**
3131
* Index action
3232
*
33-
* @return void
33+
* @return \Magento\Framework\Controller\ResultInterface
3434
*/
3535
public function execute()
3636
{

app/code/Magento/Cms/Controller/Adminhtml/Block/NewAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
/**
3131
* Create new CMS block
3232
*
33-
* @return void
33+
* @return \Magento\Framework\Controller\ResultInterface
3434
*/
3535
public function execute()
3636
{

app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
/**
3131
* Save action
3232
*
33-
* @return void
33+
* @return \Magento\Framework\Controller\ResultInterface
3434
*/
3535
public function execute()
3636
{

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ public function __construct(
3434
*/
3535
public function execute($coreRoute = null)
3636
{
37-
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
38-
$resultForward = $this->resultForwardFactory->create();
3937
$pageId = $this->_objectManager->get(
4038
'Magento\Framework\App\Config\ScopeConfigInterface'
4139
)->getValue(
4240
\Magento\Cms\Helper\Page::XML_PATH_HOME_PAGE,
4341
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4442
);
45-
if (!$this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId)) {
43+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
44+
if (!$resultPage) {
45+
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
46+
$resultForward = $this->resultForwardFactory->create();
4647
$resultForward->forward('defaultIndex');
48+
return $resultForward;
4749
}
48-
return $resultForward;
50+
return $resultPage;
4951
}
5052
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ public function __construct(
2828
/**
2929
* Render Disable cookies page
3030
*
31-
* @return void
31+
* @return \Magento\Framework\Controller\ResultInterface
3232
*/
3333
public function execute()
3434
{
35-
$resultForward = $this->resultForwardFactory->create();
3635
$pageId = $this->_objectManager->get(
3736
'Magento\Framework\App\Config\ScopeConfigInterface',
3837
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
3938
)->getValue(
4039
\Magento\Cms\Helper\Page::XML_PATH_NO_COOKIES_PAGE,
4140
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4241
);
43-
if (!$this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId)) {
42+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
43+
if (!$resultPage) {
44+
$resultForward = $this->resultForwardFactory->create();
4445
return $resultForward->forward('defaultNoCookies');
4546
}
47+
return $resultPage;
4648
}
4749
}

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

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ public function __construct(
2828
/**
2929
* View CMS page action
3030
*
31-
* @return \Magento\Backend\Model\View\Result\ForwardFactory
31+
* @return \Magento\Framework\Controller\ResultInterface
3232
*/
3333
public function execute()
3434
{
35-
$resultForward = $this->resultForwardFactory->create();
3635
$pageId = $this->getRequest()->getParam('page_id', $this->getRequest()->getParam('id', false));
37-
if (!$this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId)) {
36+
$resultPage = $this->_objectManager->get('Magento\Cms\Helper\Page')->renderPage($this, $pageId);
37+
if (!$resultPage) {
38+
$resultForward = $this->resultForwardFactory->create();
3839
return $resultForward->forward('noroute');
3940
}
41+
return $resultPage;
4042
}
4143
}

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

100644100755
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class Page extends \Magento\Framework\App\Helper\AbstractHelper
8080
*/
8181
protected $pageConfig;
8282

83+
/**
84+
* @var \Magento\Framework\View\Result\PageFactory
85+
*/
86+
protected $resultPageFactory;
87+
8388
/**
8489
* Constructor
8590
*
@@ -93,6 +98,7 @@ class Page extends \Magento\Framework\App\Helper\AbstractHelper
9398
* @param \Magento\Framework\Escaper $escaper
9499
* @param \Magento\Framework\App\ViewInterface $view
95100
* @param \Magento\Framework\View\Page\Config $pageConfig
101+
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
96102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
97103
*/
98104
public function __construct(
@@ -105,7 +111,8 @@ public function __construct(
105111
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
106112
\Magento\Framework\Escaper $escaper,
107113
\Magento\Framework\App\ViewInterface $view,
108-
\Magento\Framework\View\Page\Config $pageConfig
114+
\Magento\Framework\View\Page\Config $pageConfig,
115+
\Magento\Framework\View\Result\PageFactory $resultPageFactory
109116
) {
110117
$this->messageManager = $messageManager;
111118
$this->_view = $view;
@@ -117,6 +124,7 @@ public function __construct(
117124
$this->_localeDate = $localeDate;
118125
$this->_escaper = $escaper;
119126
$this->pageConfig = $pageConfig;
127+
$this->resultPageFactory = $resultPageFactory;
120128
parent::__construct($context);
121129
}
122130

@@ -127,7 +135,7 @@ public function __construct(
127135
*
128136
* @param Action $action
129137
* @param int $pageId
130-
* @return bool
138+
* @return bool|\Magento\Framework\View\Result\Page
131139
*/
132140
public function renderPage(Action $action, $pageId = null)
133141
{
@@ -139,12 +147,12 @@ public function renderPage(Action $action, $pageId = null)
139147
*
140148
* @param Action $action
141149
* @param int $pageId
142-
* @param bool $renderLayout
143-
* @return bool
150+
* @param bool $returnPage
151+
* @return bool|\Magento\Framework\View\Result\Page
144152
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
145153
* @SuppressWarnings(PHPMD.NPathComplexity)
146154
*/
147-
protected function _renderPage(Action $action, $pageId = null, $renderLayout = true)
155+
protected function _renderPage(Action $action, $pageId = null, $returnPage = true)
148156
{
149157
if (!is_null($pageId) && $pageId !== $this->_page->getId()) {
150158
$delimiterPosition = strrpos($pageId, '|');
@@ -173,7 +181,8 @@ protected function _renderPage(Action $action, $pageId = null, $renderLayout = t
173181
$this->_design->setDesignTheme($this->_page->getCustomTheme());
174182
}
175183
}
176-
$resultPage = $this->_view->getPage();
184+
/** @var \Magento\Framework\View\Result\Page $resultPage */
185+
$resultPage = $this->resultPageFactory->create();
177186
if ($this->_page->getPageLayout()) {
178187
if ($this->_page->getCustomPageLayout()
179188
&& $this->_page->getCustomPageLayout() != 'empty'
@@ -214,8 +223,8 @@ protected function _renderPage(Action $action, $pageId = null, $renderLayout = t
214223
$messageBlock->addStorageType($this->messageManager->getDefaultGroup());
215224
$messageBlock->addMessages($this->messageManager->getMessages(true));
216225

217-
if ($renderLayout) {
218-
$this->_view->renderLayout();
226+
if ($returnPage) {
227+
return $resultPage;
219228
}
220229

221230
return true;
@@ -229,7 +238,7 @@ protected function _renderPage(Action $action, $pageId = null, $renderLayout = t
229238
* @param Action $action
230239
* @param int $pageId
231240
* @param bool $renderLayout
232-
* @return bool
241+
* @return bool|\Magento\Framework\View\Result\Page
233242
*/
234243
public function renderPageExtended(Action $action, $pageId = null, $renderLayout = true)
235244
{

0 commit comments

Comments
 (0)