-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-7133: Implement ActionInterface for \
cms/page/view\
#27298
- Merge Pull Request #27298 from lbajsarowicz/magento2:refactor/cms-page-view - Merged commits: 1. f49060b 2. 4fd4f99 3. 4a7adeb
- Loading branch information
Showing
3 changed files
with
92 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,78 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Cms\Controller\Page; | ||
|
||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Cms\Helper\Page as PageHelper; | ||
use Magento\Framework\App\Action\HttpGetActionInterface; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\ForwardFactory; | ||
use Magento\Framework\Controller\ResultInterface; | ||
|
||
/** | ||
* Custom page for storefront. Needs to be accessible by POST because of the store switching. | ||
*/ | ||
class View extends Action implements HttpGetActionInterface, HttpPostActionInterface | ||
class View implements HttpGetActionInterface, HttpPostActionInterface | ||
{ | ||
/** | ||
* @var \Magento\Framework\Controller\Result\ForwardFactory | ||
* @var ForwardFactory | ||
*/ | ||
protected $resultForwardFactory; | ||
|
||
/** | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var PageHelper | ||
*/ | ||
private $pageHelper; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param PageHelper $pageHelper | ||
* @param ForwardFactory $resultForwardFactory | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory | ||
RequestInterface $request, | ||
PageHelper $pageHelper, | ||
ForwardFactory $resultForwardFactory | ||
) { | ||
$this->request = $request; | ||
$this->pageHelper = $pageHelper; | ||
$this->resultForwardFactory = $resultForwardFactory; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* View CMS page action | ||
* | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
* @return ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$pageId = $this->getRequest()->getParam('page_id', $this->getRequest()->getParam('id', false)); | ||
$resultPage = $this->_objectManager->get(\Magento\Cms\Helper\Page::class)->prepareResultPage($this, $pageId); | ||
$resultPage = $this->pageHelper->prepareResultPage($this, $this->getPageId()); | ||
if (!$resultPage) { | ||
$resultForward = $this->resultForwardFactory->create(); | ||
return $resultForward->forward('noroute'); | ||
} | ||
return $resultPage; | ||
} | ||
|
||
/** | ||
* Returns Page ID if provided or null | ||
* | ||
* @return int|null | ||
*/ | ||
private function getPageId(): ?int | ||
{ | ||
$id = $this->request->getParam('page_id') ?? $this->request->getParam('id'); | ||
|
||
return $id ? (int)$id : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters