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
7 
8 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
9 
10 class Edit extends \Magento\Cms\Controller\Adminhtml\Block implements HttpGetActionInterface
11 {
15  protected $resultPageFactory;
16 
22  public function __construct(
23  \Magento\Backend\App\Action\Context $context,
24  \Magento\Framework\Registry $coreRegistry,
25  \Magento\Framework\View\Result\PageFactory $resultPageFactory
26  ) {
27  $this->resultPageFactory = $resultPageFactory;
28  parent::__construct($context, $coreRegistry);
29  }
30 
37  public function execute()
38  {
39  // 1. Get ID and create model
40  $id = $this->getRequest()->getParam('block_id');
41  $model = $this->_objectManager->create(\Magento\Cms\Model\Block::class);
42 
43  // 2. Initial checking
44  if ($id) {
45  $model->load($id);
46  if (!$model->getId()) {
47  $this->messageManager->addErrorMessage(__('This block no longer exists.'));
49  $resultRedirect = $this->resultRedirectFactory->create();
50  return $resultRedirect->setPath('*/*/');
51  }
52  }
53 
54  $this->_coreRegistry->register('cms_block', $model);
55 
56  // 5. Build edit form
58  $resultPage = $this->resultPageFactory->create();
59  $this->initPage($resultPage)->addBreadcrumb(
60  $id ? __('Edit Block') : __('New Block'),
61  $id ? __('Edit Block') : __('New Block')
62  );
63  $resultPage->getConfig()->getTitle()->prepend(__('Blocks'));
64  $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Block'));
65  return $resultPage;
66  }
67 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
Definition: Edit.php:22