-
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.
magento/module-cms Replace inheritance with Composition
cms/page/view
- Loading branch information
1 parent
a66a2d5
commit f49060b
Showing
3 changed files
with
93 additions
and
53 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