Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
11 
12 class Edit extends \Magento\Backend\App\Action implements HttpGetActionInterface
13 {
19  const ADMIN_RESOURCE = 'Magento_Cms::save';
20 
26  protected $_coreRegistry;
27 
31  protected $resultPageFactory;
32 
38  public function __construct(
39  Action\Context $context,
40  \Magento\Framework\View\Result\PageFactory $resultPageFactory,
41  \Magento\Framework\Registry $registry
42  ) {
43  $this->resultPageFactory = $resultPageFactory;
44  $this->_coreRegistry = $registry;
45  parent::__construct($context);
46  }
47 
53  protected function _initAction()
54  {
55  // load layout, set active menu and breadcrumbs
57  $resultPage = $this->resultPageFactory->create();
58  $resultPage->setActiveMenu('Magento_Cms::cms_page')
59  ->addBreadcrumb(__('CMS'), __('CMS'))
60  ->addBreadcrumb(__('Manage Pages'), __('Manage Pages'));
61  return $resultPage;
62  }
63 
70  public function execute()
71  {
72  // 1. Get ID and create model
73  $id = $this->getRequest()->getParam('page_id');
74  $model = $this->_objectManager->create(\Magento\Cms\Model\Page::class);
75 
76  // 2. Initial checking
77  if ($id) {
78  $model->load($id);
79  if (!$model->getId()) {
80  $this->messageManager->addErrorMessage(__('This page no longer exists.'));
82  $resultRedirect = $this->resultRedirectFactory->create();
83  return $resultRedirect->setPath('*/*/');
84  }
85  }
86 
87  $this->_coreRegistry->register('cms_page', $model);
88 
89  // 5. Build edit form
91  $resultPage = $this->_initAction();
92  $resultPage->addBreadcrumb(
93  $id ? __('Edit Page') : __('New Page'),
94  $id ? __('Edit Page') : __('New Page')
95  );
96  $resultPage->getConfig()->getTitle()->prepend(__('Pages'));
97  $resultPage->getConfig()->getTitle()
98  ->prepend($model->getId() ? $model->getTitle() : __('New Page'));
99 
100  return $resultPage;
101  }
102 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
__construct(Action\Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Registry $registry)
Definition: Edit.php:38