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 
13 {
19  const ADMIN_RESOURCE = 'Magento_Search::synonyms';
20 
24  private $logger;
25 
29  private $synGroupRepository;
30 
38  public function __construct(
39  \Magento\Backend\App\Action\Context $context,
40  \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository,
41  \Psr\Log\LoggerInterface $logger
42  ) {
43  $this->synGroupRepository = $synGroupRepository;
44  $this->logger = $logger;
45  parent::__construct($context);
46  }
47 
53  public function execute()
54  {
55  $id = $this->getRequest()->getParam('group_id');
57  $resultRedirect = $this->resultRedirectFactory->create();
58  if ($id) {
59  try {
61  $synGroupModel = $this->synGroupRepository->get($id);
62  $this->synGroupRepository->delete($synGroupModel);
63  $this->messageManager->addSuccessMessage(__('The synonym group has been deleted.'));
64  } catch (\Magento\Framework\Exception\LocalizedException $e) {
65  $this->messageManager->addErrorMessage($e->getMessage());
66  $this->logger->error($e);
67  } catch (\Exception $e) {
68  $this->messageManager->addErrorMessage(
69  __('An error was encountered while performing delete operation.')
70  );
71  $this->logger->error($e);
72  }
73  } else {
74  $this->messageManager->addErrorMessage(__('We can\'t find a synonym group to delete.'));
75  }
76 
77  return $resultRedirect->setPath('*/*/');
78  }
79 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
$logger
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Search\Api\SynonymGroupRepositoryInterface $synGroupRepository, \Psr\Log\LoggerInterface $logger)
Definition: Delete.php:38