Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Preview.php
Go to the documentation of this file.
1 <?php
13 
19 {
23  protected $_maliciousCode;
24 
28  protected $_emailFactory;
29 
33  protected $profilerName = 'email_template_proccessing';
34 
41  public function __construct(
42  \Magento\Backend\Block\Template\Context $context,
43  \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
44  \Magento\Email\Model\TemplateFactory $emailFactory,
45  array $data = []
46  ) {
47  $this->_maliciousCode = $maliciousCode;
48  $this->_emailFactory = $emailFactory;
49  parent::__construct($context, $data);
50  }
51 
57  protected function _toHtml()
58  {
59  $storeId = $this->getAnyStoreView()->getId();
61  $template = $this->_emailFactory->create();
62 
63  if ($id = (int)$this->getRequest()->getParam('id')) {
64  $template->load($id);
65  } else {
66  $template->setTemplateType($this->getRequest()->getParam('type'));
67  $template->setTemplateText($this->getRequest()->getParam('text'));
68  $template->setTemplateStyles($this->getRequest()->getParam('styles'));
69  }
70 
71  $template->setTemplateText($this->_maliciousCode->filter($template->getTemplateText()));
72 
73  \Magento\Framework\Profiler::start($this->profilerName);
74 
75  $template->emulateDesign($storeId);
76  $templateProcessed = $this->_appState->emulateAreaCode(
77  \Magento\Email\Model\AbstractTemplate::DEFAULT_DESIGN_AREA,
78  [$template, 'getProcessedTemplate']
79  );
80  $template->revertDesign();
81 
82  if ($template->isPlain()) {
83  $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
84  }
85 
86  \Magento\Framework\Profiler::stop($this->profilerName);
87 
88  return $templateProcessed;
89  }
90 
96  protected function getAnyStoreView()
97  {
98  $store = $this->_storeManager->getDefaultStoreView();
99  if ($store) {
100  return $store;
101  }
102  foreach ($this->_storeManager->getStores() as $store) {
103  return $store;
104  }
105  return null;
106  }
107 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode, \Magento\Email\Model\TemplateFactory $emailFactory, array $data=[])
Definition: Preview.php:41
$id
Definition: fieldset.phtml:14
$template
Definition: export.php:12