cookieRepository = $cookieRepository; } /** * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $id = (int) $this->getRequest()->getParam('id'); if ($id) { try { $this->cookieRepository->deleteById($id); $this->messageManager->addSuccessMessage(__('You deleted the cookie.')); return $resultRedirect->setPath('*/*/'); } catch (\Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); return $resultRedirect->setPath('*/*/edit', ['id' => $id]); } } $this->messageManager->addErrorMessage(__('We can\'t find a cookie to delete.')); return $resultRedirect->setPath('*/*/'); } }