Skip to content

Inconsistency: the «cms_page_prepare_save» event is fired by a controller on a CMS page saving in the backend, but no any similar event is fired on a CMS block saving #2249

@dmitrii-fediuk

Description

@dmitrii-fediuk

Similar to #2248

The «cms_page_prepare_save» event firing :

$this->_eventManager->dispatch(
'cms_page_prepare_save',
['page' => $model, 'request' => $this->getRequest()]
);

There is no similar event for block:

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('*/*/');
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions