resultPageFactory = $resultPageFactory; parent::__construct($context, $coreRegistry); } /** * Edit CMS block * * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('block_id'); $model = $this->_objectManager->create(\Magento\Cms\Model\Block::class); // 2. Initial checking if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This block no longer exists.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } $this->_coreRegistry->register('cms_block', $model); // 5. Build edit form /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->initPage($resultPage)->addBreadcrumb( $id ? __('Edit Block') : __('New Block'), $id ? __('Edit Block') : __('New Block') ); $resultPage->getConfig()->getTitle()->prepend(__('Blocks')); $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Block')); return $resultPage; } }