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 {
16  public function execute()
17  {
18  $template = $this->_initTemplate('id');
19  if ($template->getId()) {
20  try {
21  // check if the template is currently used
22  if (count($template->getSystemConfigPathsWhereCurrentlyUsed()) == 0) {
23  $template->delete();
24  // display success message
25  $this->messageManager->addSuccessMessage(__('You deleted the email template.'));
26  $this->_objectManager->get(\Magento\Framework\App\ReinitableConfig::class)->reinit();
27  // go to grid
28  $this->_redirect('adminhtml/*/');
29  return;
30  }
31  // display error message
32  $this->messageManager->addErrorMessage(__('The email template is currently being used.'));
33  // redirect to edit form
34  $this->_redirect('adminhtml/*/edit', ['id' => $template->getId()]);
35  return;
36  } catch (\Magento\Framework\Exception\LocalizedException $e) {
37  $this->messageManager->addErrorMessage($e->getMessage());
38  } catch (\Exception $e) {
39  $this->messageManager->addErrorMessage(
40  __('We can\'t delete email template data right now. Please review log and try again.')
41  );
42  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
43  // save data in session
44  $this->_objectManager->get(
45  \Magento\Backend\Model\Session::class
46  )->setFormData(
47  $this->getRequest()->getParams()
48  );
49  // redirect to edit form
50  $this->_redirect('adminhtml/*/edit', ['id' => $template->getId()]);
51  return;
52  }
53  }
54  // display error message
55  $this->messageManager->addErrorMessage(__('We can\'t find an email template to delete.'));
56  // go to grid
57  $this->_redirect('adminhtml/*/');
58  }
59 }
_initTemplate($idFieldName='template_id')
Definition: Template.php:46
__()
Definition: __.php:13
$template
Definition: export.php:12