14
14
/**
15
15
* Preview controller to render blocks preview on Stage
16
16
*
17
- * This isn't placed within the adminhtml folder as it has to extend from the front-end controllers app action to
18
- * ensure the content is rendered in the storefront scope.
19
- *
20
17
* @api
21
18
*/
22
19
class Preview extends \Magento \Backend \App \Action implements HttpPostActionInterface
@@ -29,72 +26,24 @@ class Preview extends \Magento\Backend\App\Action implements HttpPostActionInter
29
26
private $ rendererPool ;
30
27
31
28
/**
32
- * @var \Magento\Framework\App\State
33
- */
34
- private $ appState ;
35
-
36
- /**
37
- * @var \Magento\Theme\Model\View\Design
29
+ * @var \Magento\PageBuilder\Model\Stage\Preview
38
30
*/
39
- private $ design ;
40
-
41
- /**
42
- * @var \Magento\Framework\View\Design\Theme\ThemeProviderInterface
43
- */
44
- private $ themeProvider ;
45
-
46
- /**
47
- * @var \Magento\Store\Model\StoreManagerInterface
48
- */
49
- private $ storeManager ;
50
-
51
- /**
52
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
53
- */
54
- private $ scopeConfig ;
55
-
56
- /**
57
- * @var \Magento\Store\Model\App\Emulation
58
- */
59
- private $ emulation ;
60
-
61
- /**
62
- * @var \Magento\PageBuilder\Model\Stage\PreviewRegistry
63
- */
64
- private $ previewRegistry ;
31
+ private $ preview ;
65
32
66
33
/**
67
34
* @param \Magento\Backend\App\Action\Context $context
68
35
* @param \Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
69
- * @param \Magento\Store\Model\App\Emulation $emulation
70
- * @param \Magento\Framework\App\State $appState
71
- * @param \Magento\Framework\View\DesignInterface $design
72
- * @param \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider
73
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
74
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
75
- * @param \Magento\PageBuilder\Model\Stage\PreviewRegistry $previewRegistry
36
+ * @param \Magento\PageBuilder\Model\Stage\Preview $preview
76
37
*/
77
38
public function __construct (
78
39
\Magento \Backend \App \Action \Context $ context ,
79
40
\Magento \PageBuilder \Model \Stage \RendererPool $ rendererPool ,
80
- \Magento \Store \Model \App \Emulation $ emulation ,
81
- \Magento \Framework \App \State $ appState ,
82
- \Magento \Framework \View \DesignInterface $ design ,
83
- \Magento \Framework \View \Design \Theme \ThemeProviderInterface $ themeProvider ,
84
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
85
- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
86
- \Magento \PageBuilder \Model \Stage \PreviewRegistry $ previewRegistry
41
+ \Magento \PageBuilder \Model \Stage \Preview $ preview
87
42
) {
88
43
parent ::__construct ($ context );
89
44
90
45
$ this ->rendererPool = $ rendererPool ;
91
- $ this ->emulation = $ emulation ;
92
- $ this ->appState = $ appState ;
93
- $ this ->design = $ design ;
94
- $ this ->themeProvider = $ themeProvider ;
95
- $ this ->storeManager = $ storeManager ;
96
- $ this ->scopeConfig = $ scopeConfig ;
97
- $ this ->previewRegistry = $ previewRegistry ;
46
+ $ this ->preview = $ preview ;
98
47
}
99
48
100
49
/**
@@ -105,20 +54,8 @@ public function __construct(
105
54
*/
106
55
public function execute ()
107
56
{
108
- $ defaultStore = $ this ->storeManager ->getDefaultStoreView ();
109
- $ this ->previewRegistry ->setIsPreview (true );
110
- $ this ->emulation ->startEnvironmentEmulation ($ defaultStore ->getId ());
111
-
112
- return $ this ->appState ->emulateAreaCode (
113
- $ this ->previewRegistry ->getPreviewArea (),
57
+ return $ this ->preview ->startPreviewMode (
114
58
function () {
115
- $ themeId = $ this ->scopeConfig ->getValue (
116
- 'design/theme/theme_id ' ,
117
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE
118
- );
119
- $ theme = $ this ->themeProvider ->getThemeById ($ themeId );
120
- $ this ->design ->setDesignTheme ($ theme , $ this ->previewRegistry ->getPreviewArea ());
121
-
122
59
$ pageResult = $ this ->resultFactory ->create (ResultFactory::TYPE_PAGE );
123
60
// Some template filters and directive processors expect this to be called in order to function.
124
61
$ pageResult ->initLayout ();
@@ -127,10 +64,7 @@ function () {
127
64
$ renderer = $ this ->rendererPool ->getRenderer ($ params ['role ' ]);
128
65
$ result = ['data ' => $ renderer ->render ($ params )];
129
66
130
- $ response = $ this ->resultFactory ->create (ResultFactory::TYPE_JSON )->setData ($ result );
131
- $ this ->emulation ->stopEnvironmentEmulation ();
132
- $ this ->previewRegistry ->setIsPreview (false );
133
- return $ response ;
67
+ return $ this ->resultFactory ->create (ResultFactory::TYPE_JSON )->setData ($ result );
134
68
}
135
69
);
136
70
}
0 commit comments