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
8 
10 
15 {
21  public function execute()
22  {
23  $this->_view->loadLayout();
24 
25  $data = $this->getRequest()->getParams();
26  $isEmptyRequestData = empty($data) || !isset($data['id']);
27  $isEmptyPreviewData = !$this->_getSession()->hasPreviewData() || empty($this->_getSession()->getPreviewData());
28 
29  if ($isEmptyRequestData && $isEmptyPreviewData) {
30  $this->_forward('noroute');
31  return $this;
32  }
33 
34  // set default value for selected store
36  $storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManager::class);
37  $defaultStore = $storeManager->getDefaultStoreView();
38  if (!$defaultStore) {
39  $allStores = $storeManager->getStores();
40  if (isset($allStores[0])) {
41  $defaultStore = $allStores[0];
42  }
43  }
44  $data['preview_store_id'] = $defaultStore ? $defaultStore->getId() : null;
45  $this->_view->getLayout()->getBlock('preview_form')->setFormData($data);
46  $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Newsletter Templates'));
47  $this->_view->renderLayout();
48  }
49 }
$storeManager
__()
Definition: __.php:13
_forward($action, $controller=null, $module=null, array $params=null)