Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
18  public function execute()
19  {
21  $resultRedirect = $this->resultRedirectFactory->create();
22  // check if we know what should be deleted
23  $id = $this->getRequest()->getParam('block_id');
24  if ($id) {
25  try {
26  // init model and delete
27  $model = $this->_objectManager->create(\Magento\Cms\Model\Block::class);
28  $model->load($id);
29  $model->delete();
30  // display success message
31  $this->messageManager->addSuccessMessage(__('You deleted the block.'));
32  // go to grid
33  return $resultRedirect->setPath('*/*/');
34  } catch (\Exception $e) {
35  // display error message
36  $this->messageManager->addErrorMessage($e->getMessage());
37  // go back to edit form
38  return $resultRedirect->setPath('*/*/edit', ['block_id' => $id]);
39  }
40  }
41  // display error message
42  $this->messageManager->addErrorMessage(__('We can\'t find a block to delete.'));
43  // go to grid
44  return $resultRedirect->setPath('*/*/');
45  }
46 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13