Delete.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Controller\Adminhtml\Term;
  7. use Magento\Framework\App\Action\HttpPostActionInterface;
  8. use Magento\Search\Controller\Adminhtml\Term as TermController;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class Delete extends TermController implements HttpPostActionInterface
  11. {
  12. /**
  13. * @return \Magento\Backend\Model\View\Result\Redirect
  14. */
  15. public function execute()
  16. {
  17. $id = $this->getRequest()->getParam('id');
  18. /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
  19. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  20. if ($id) {
  21. try {
  22. $model = $this->_objectManager->create(\Magento\Search\Model\Query::class);
  23. $model->setId($id);
  24. $model->delete();
  25. $this->messageManager->addSuccessMessage(__('You deleted the search.'));
  26. $resultRedirect->setPath('search/*/');
  27. return $resultRedirect;
  28. } catch (\Exception $e) {
  29. $this->messageManager->addErrorMessage($e->getMessage());
  30. $resultRedirect->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]);
  31. return $resultRedirect;
  32. }
  33. }
  34. $this->messageManager->addErrorMessage(__('We can\'t find a search term to delete.'));
  35. $resultRedirect->setPath('search/*/');
  36. return $resultRedirect;
  37. }
  38. }