1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\PageCache\Controller\Block;
class Render extends \Magento\PageCache\Controller\Block
{
/**
* Returns block content depends on ajax request
*
* @return void
*/
public function execute()
{
if (!$this->getRequest()->isAjax()) {
$this->_forward('noroute');
return;
}
// disable profiling during private content handling AJAX call
\Magento\Framework\Profiler::reset();
$currentRoute = $this->getRequest()->getRouteName();
$currentControllerName = $this->getRequest()->getControllerName();
$currentActionName = $this->getRequest()->getActionName();
$currentRequestUri = $this->getRequest()->getRequestUri();
$origRequest = $this->getRequest()->getParam('originalRequest');
if ($origRequest && is_string($origRequest)) {
$origRequest = json_decode($origRequest, true);
}
$this->getRequest()->setRouteName($origRequest['route']);
$this->getRequest()->setControllerName($origRequest['controller']);
$this->getRequest()->setActionName($origRequest['action']);
$this->getRequest()->setRequestUri($origRequest['uri']);
/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
$blocks = $this->_getBlocks();
$data = [];
foreach ($blocks as $blockName => $blockInstance) {
$data[$blockName] = $blockInstance->toHtml();
}
$this->getRequest()->setRouteName($currentRoute);
$this->getRequest()->setControllerName($currentControllerName);
$this->getRequest()->setActionName($currentActionName);
$this->getRequest()->setRequestUri($currentRequestUri);
$this->getResponse()->setPrivateHeaders(\Magento\PageCache\Helper\Data::PRIVATE_MAX_AGE_CACHE);
$this->translateInline->processResponseBody($data);
$this->getResponse()->appendBody(json_encode($data));
}
}