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 {
16  public function execute()
17  {
18  $this->_view->loadLayout();
19  $data = $this->getRequest()->getParams();
20 
21  $isEmptyRequestData = empty($data) || !isset($data['id']);
22  $isEmptyPreviewData = !$this->_getSession()->hasPreviewData() || empty($this->_getSession()->getPreviewData());
23 
24  if ($isEmptyRequestData && $isEmptyPreviewData) {
25  $this->_forward('noroute');
26  return;
27  }
28 
29  // set default value for selected store
31  $storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManager::class);
32  $defaultStore = $storeManager->getDefaultStoreView();
33  if (!$defaultStore) {
34  $allStores = $storeManager->getStores();
35  if (isset($allStores[0])) {
36  $defaultStore = $allStores[0];
37  }
38  }
39  $data['preview_store_id'] = $defaultStore ? $defaultStore->getId() : null;
40 
41  $this->_view->getLayout()->getBlock('preview_form')->setFormData($data);
42  $this->_view->renderLayout();
43  }
44 }
$storeManager
_forward($action, $controller=null, $module=null, array $params=null)