Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Load.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
13 
17 class Load extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
18 {
22  protected $resultJsonFactory;
23 
28  protected $sectionIdentifier;
29 
33  protected $sectionPool;
34 
38  private $escaper;
39 
47  public function __construct(
48  Context $context,
52  \Magento\Framework\Escaper $escaper = null
53  ) {
54  parent::__construct($context);
55  $this->resultJsonFactory = $resultJsonFactory;
56  $this->sectionIdentifier = $sectionIdentifier;
57  $this->sectionPool = $sectionPool;
58  $this->escaper = $escaper ?: $this->_objectManager->get(\Magento\Framework\Escaper::class);
59  }
60 
64  public function execute()
65  {
67  $resultJson = $this->resultJsonFactory->create();
68  $resultJson->setHeader('Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store', true);
69  $resultJson->setHeader('Pragma', 'no-cache', true);
70  try {
71  $sectionNames = $this->getRequest()->getParam('sections');
72  $sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null;
73 
74  $updateSectionId = $this->getRequest()->getParam('update_section_id');
75  if ('false' === $updateSectionId) {
76  $updateSectionId = false;
77  }
78  $response = $this->sectionPool->getSectionsData($sectionNames, (bool)$updateSectionId);
79  } catch (\Exception $e) {
80  $resultJson->setStatusHeader(
81  \Zend\Http\Response::STATUS_CODE_400,
82  \Zend\Http\AbstractMessage::VERSION_11,
83  'Bad Request'
84  );
85  $response = ['message' => $this->escaper->escapeHtml($e->getMessage())];
86  }
87 
88  return $resultJson->setData($response);
89  }
90 }
__construct(Context $context, JsonFactory $resultJsonFactory, Identifier $sectionIdentifier, SectionPoolInterface $sectionPool, \Magento\Framework\Escaper $escaper=null)
Definition: Load.php:47
$response
Definition: 404.php:11