Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultTemplate.php
Go to the documentation of this file.
1 <?php
8 
10 {
14  private $emailConfig;
15 
19  private $serializer;
20 
28  public function __construct(
29  \Magento\Backend\App\Action\Context $context,
30  \Magento\Framework\Registry $coreRegistry,
31  \Magento\Email\Model\Template\Config $emailConfig,
32  \Magento\Framework\Serialize\Serializer\Json $serializer = null
33  ) {
34  $this->emailConfig = $emailConfig;
35  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
36  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
37  parent::__construct($context, $coreRegistry);
38  }
39 
46  public function execute()
47  {
48  $this->_view->loadLayout();
49  $template = $this->_initTemplate('id');
50  $templateId = $this->getRequest()->getParam('code');
51  try {
52  $parts = $this->emailConfig->parseTemplateIdParts($templateId);
53  $templateId = $parts['templateId'];
54  $theme = $parts['theme'];
55 
56  if ($theme) {
57  $template->setForcedTheme($templateId, $theme);
58  }
59  $template->setForcedArea($templateId);
60 
61  $template->loadDefault($templateId);
62  $template->setData('orig_template_code', $templateId);
63  $template->setData(
64  'template_variables',
65  $this->serializer->serialize($template->getVariablesOptionArray(true))
66  );
67 
68  $templateBlock = $this->_view->getLayout()->createBlock(
69  \Magento\Email\Block\Adminhtml\Template\Edit::class,
70  'template_edit',
71  [
72  'data' => [
73  'email_template' => $template
74  ]
75  ]
76  );
77  $template->setData('orig_template_currently_used_for', $templateBlock->getCurrentlyUsedForPaths(false));
78 
79  $this->getResponse()->representJson(
80  $this->serializer->serialize($template->getData())
81  );
82  } catch (\Exception $e) {
83  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
84  }
85  }
86 }
_initTemplate($idFieldName='template_id')
Definition: Template.php:46
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
$templateId
Definition: queue.php:15
$theme
$template
Definition: export.php:12