@@ -129,14 +129,95 @@ public function __construct(
129
129
parent ::__construct ($ context );
130
130
}
131
131
132
+ /**
133
+ * Return result CMS page
134
+ *
135
+ * @param Action $action
136
+ * @param null $pageId
137
+ * @return \Magento\Framework\View\Result\Page|bool
138
+ */
139
+ public function prepareResultPage (Action $ action , $ pageId = null )
140
+ {
141
+ if (!is_null ($ pageId ) && $ pageId !== $ this ->_page ->getId ()) {
142
+ $ delimiterPosition = strrpos ($ pageId , '| ' );
143
+ if ($ delimiterPosition ) {
144
+ $ pageId = substr ($ pageId , 0 , $ delimiterPosition );
145
+ }
146
+
147
+ $ this ->_page ->setStoreId ($ this ->_storeManager ->getStore ()->getId ());
148
+ if (!$ this ->_page ->load ($ pageId )) {
149
+ return false ;
150
+ }
151
+ }
152
+
153
+ if (!$ this ->_page ->getId ()) {
154
+ return false ;
155
+ }
156
+
157
+ $ inRange = $ this ->_localeDate ->isScopeDateInInterval (
158
+ null ,
159
+ $ this ->_page ->getCustomThemeFrom (),
160
+ $ this ->_page ->getCustomThemeTo ()
161
+ );
162
+
163
+ if ($ this ->_page ->getCustomTheme ()) {
164
+ if ($ inRange ) {
165
+ $ this ->_design ->setDesignTheme ($ this ->_page ->getCustomTheme ());
166
+ }
167
+ }
168
+ /** @var \Magento\Framework\View\Result\Page $resultPage */
169
+ $ resultPage = $ this ->resultPageFactory ->create ();
170
+ if ($ this ->_page ->getPageLayout ()) {
171
+ if ($ this ->_page ->getCustomPageLayout ()
172
+ && $ this ->_page ->getCustomPageLayout () != 'empty '
173
+ && $ inRange
174
+ ) {
175
+ $ handle = $ this ->_page ->getCustomPageLayout ();
176
+ } else {
177
+ $ handle = $ this ->_page ->getPageLayout ();
178
+ }
179
+ $ resultPage ->getConfig ()->setPageLayout ($ handle );
180
+ }
181
+ $ resultPage ->initLayout ();
182
+ $ resultPage ->addHandle ('cms_page_view ' );
183
+ $ resultPage ->addPageLayoutHandles (['id ' => $ this ->_page ->getIdentifier ()]);
184
+
185
+ $ this ->_eventManager ->dispatch (
186
+ 'cms_page_render ' ,
187
+ ['page ' => $ this ->_page , 'controller_action ' => $ action ]
188
+ );
189
+
190
+ if ($ this ->_page ->getCustomLayoutUpdateXml () && $ inRange ) {
191
+ $ layoutUpdate = $ this ->_page ->getCustomLayoutUpdateXml ();
192
+ } else {
193
+ $ layoutUpdate = $ this ->_page ->getLayoutUpdateXml ();
194
+ }
195
+ if (!empty ($ layoutUpdate )) {
196
+ $ resultPage ->getLayout ()->getUpdate ()->addUpdate ($ layoutUpdate );
197
+ }
198
+
199
+ $ contentHeadingBlock = $ resultPage ->getLayout ()->getBlock ('page_content_heading ' );
200
+ if ($ contentHeadingBlock ) {
201
+ $ contentHeading = $ this ->_escaper ->escapeHtml ($ this ->_page ->getContentHeading ());
202
+ $ contentHeadingBlock ->setContentHeading ($ contentHeading );
203
+ }
204
+
205
+ /* @TODO: Move catalog and checkout storage types to appropriate modules */
206
+ $ messageBlock = $ resultPage ->getLayout ()->getMessagesBlock ();
207
+ $ messageBlock ->addStorageType ($ this ->messageManager ->getDefaultGroup ());
208
+ $ messageBlock ->addMessages ($ this ->messageManager ->getMessages (true ));
209
+
210
+ return $ resultPage ;
211
+ }
212
+
132
213
/**
133
214
* Renders CMS page on front end
134
215
*
135
216
* Call from controller action
136
217
*
137
218
* @param Action $action
138
219
* @param int $pageId
139
- * @return bool|\Magento\Framework\View\Result\Page
220
+ * @return bool
140
221
*/
141
222
public function renderPage (Action $ action , $ pageId = null )
142
223
{
@@ -148,12 +229,12 @@ public function renderPage(Action $action, $pageId = null)
148
229
*
149
230
* @param Action $action
150
231
* @param int $pageId
151
- * @param bool $returnPage
152
- * @return bool|\Magento\Framework\View\Result\Page
232
+ * @param bool $renderLayout
233
+ * @return bool
153
234
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
154
235
* @SuppressWarnings(PHPMD.NPathComplexity)
155
236
*/
156
- protected function _renderPage (Action $ action , $ pageId = null , $ returnPage = true )
237
+ protected function _renderPage (Action $ action , $ pageId = null , $ renderLayout = true )
157
238
{
158
239
if (!is_null ($ pageId ) && $ pageId !== $ this ->_page ->getId ()) {
159
240
$ delimiterPosition = strrpos ($ pageId , '| ' );
@@ -182,8 +263,7 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
182
263
$ this ->_design ->setDesignTheme ($ this ->_page ->getCustomTheme ());
183
264
}
184
265
}
185
- /** @var \Magento\Framework\View\Result\Page $resultPage */
186
- $ resultPage = $ this ->resultPageFactory ->create ();
266
+ $ resultPage = $ this ->_view ->getPage ();
187
267
if ($ this ->_page ->getPageLayout ()) {
188
268
if ($ this ->_page ->getCustomPageLayout ()
189
269
&& $ this ->_page ->getCustomPageLayout () != 'empty '
@@ -224,8 +304,8 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
224
304
$ messageBlock ->addStorageType ($ this ->messageManager ->getDefaultGroup ());
225
305
$ messageBlock ->addMessages ($ this ->messageManager ->getMessages (true ));
226
306
227
- if ($ returnPage ) {
228
- return $ resultPage ;
307
+ if ($ renderLayout ) {
308
+ $ this -> _view -> renderLayout () ;
229
309
}
230
310
231
311
return true ;
@@ -239,7 +319,7 @@ protected function _renderPage(Action $action, $pageId = null, $returnPage = tru
239
319
* @param Action $action
240
320
* @param int $pageId
241
321
* @param bool $renderLayout
242
- * @return bool|\Magento\Framework\View\Result\Page
322
+ * @return bool
243
323
*/
244
324
public function renderPageExtended (Action $ action , $ pageId = null , $ renderLayout = true )
245
325
{
0 commit comments