View.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Cms\Controller\Page;
  8. use Magento\Framework\App\Action\HttpPostActionInterface;
  9. use Magento\Framework\App\Action\HttpGetActionInterface;
  10. use Magento\Framework\App\Action\Action;
  11. /**
  12. * Custom page for storefront. Needs to be accessible by POST because of the store switching.
  13. */
  14. class View extends Action implements HttpGetActionInterface, HttpPostActionInterface
  15. {
  16. /**
  17. * @var \Magento\Framework\Controller\Result\ForwardFactory
  18. */
  19. protected $resultForwardFactory;
  20. /**
  21. * @param \Magento\Framework\App\Action\Context $context
  22. * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
  23. */
  24. public function __construct(
  25. \Magento\Framework\App\Action\Context $context,
  26. \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
  27. ) {
  28. $this->resultForwardFactory = $resultForwardFactory;
  29. parent::__construct($context);
  30. }
  31. /**
  32. * View CMS page action
  33. *
  34. * @return \Magento\Framework\Controller\ResultInterface
  35. */
  36. public function execute()
  37. {
  38. $pageId = $this->getRequest()->getParam('page_id', $this->getRequest()->getParam('id', false));
  39. $resultPage = $this->_objectManager->get(\Magento\Cms\Helper\Page::class)->prepareResultPage($this, $pageId);
  40. if (!$resultPage) {
  41. $resultForward = $this->resultForwardFactory->create();
  42. return $resultForward->forward('noroute');
  43. }
  44. return $resultPage;
  45. }
  46. }