-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Description
Similar to #2248
The «cms_page_prepare_save» event firing :
magento2/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php
Lines 57 to 60 in f578e54
| $this->_eventManager->dispatch( | |
| 'cms_page_prepare_save', | |
| ['page' => $model, 'request' => $this->getRequest()] | |
| ); |
There is no similar event for block:
magento2/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php
Lines 16 to 59 in f578e54
| public function executeInternal() | |
| { | |
| /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ | |
| $resultRedirect = $this->resultRedirectFactory->create(); | |
| // check if data sent | |
| $data = $this->getRequest()->getPostValue(); | |
| if ($data) { | |
| $id = $this->getRequest()->getParam('block_id'); | |
| $model = $this->_objectManager->create('Magento\Cms\Model\Block')->load($id); | |
| if (!$model->getId() && $id) { | |
| $this->messageManager->addError(__('This block no longer exists.')); | |
| return $resultRedirect->setPath('*/*/'); | |
| } | |
| // init model and set data | |
| $model->setData($data); | |
| // try to save it | |
| try { | |
| // save the data | |
| $model->save(); | |
| // display success message | |
| $this->messageManager->addSuccess(__('You saved the block.')); | |
| // clear previously saved data from session | |
| $this->_objectManager->get('Magento\Backend\Model\Session')->setFormData(false); | |
| // check if 'Save and Continue' | |
| if ($this->getRequest()->getParam('back')) { | |
| return $resultRedirect->setPath('*/*/edit', ['block_id' => $model->getId()]); | |
| } | |
| // go to grid | |
| return $resultRedirect->setPath('*/*/'); | |
| } catch (\Exception $e) { | |
| // display error message | |
| $this->messageManager->addError($e->getMessage()); | |
| // save data in session | |
| $this->_objectManager->get('Magento\Backend\Model\Session')->setFormData($data); | |
| // redirect to edit form | |
| return $resultRedirect->setPath('*/*/edit', ['block_id' => $this->getRequest()->getParam('block_id')]); | |
| } | |
| } | |
| return $resultRedirect->setPath('*/*/'); | |
| } |