Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Block.php
Go to the documentation of this file.
1 <?php
9 
13 
15 {
19  protected $translateInline;
20 
24  private $jsonSerializer;
25 
29  private $base64jsonSerializer;
30 
36  private $layoutCacheKey;
37 
41  private $layoutCacheKeyName = 'mage_pagecache';
42 
50  public function __construct(
51  \Magento\Framework\App\Action\Context $context,
52  \Magento\Framework\Translate\InlineInterface $translateInline,
53  Json $jsonSerializer = null,
54  Base64Json $base64jsonSerializer = null,
55  LayoutCacheKeyInterface $layoutCacheKey = null
56  ) {
57  parent::__construct($context);
58  $this->translateInline = $translateInline;
59  $this->jsonSerializer = $jsonSerializer
61  $this->base64jsonSerializer = $base64jsonSerializer
62  ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Base64Json::class);
63  $this->layoutCacheKey = $layoutCacheKey
64  ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
65  }
66 
72  protected function _getBlocks()
73  {
74  $blocks = $this->getRequest()->getParam('blocks', '');
75  $handles = $this->getRequest()->getParam('handles', '');
76 
77  if (!$handles || !$blocks) {
78  return [];
79  }
80  $blocks = $this->jsonSerializer->unserialize($blocks);
81  $handles = $this->base64jsonSerializer->unserialize($handles);
82 
83  $layout = $this->_view->getLayout();
84  $this->layoutCacheKey->addCacheKeys($this->layoutCacheKeyName);
85 
86  $this->_view->loadLayout($handles, true, true, false);
87  $data = [];
88 
89  foreach ($blocks as $blockName) {
90  $blockInstance = $layout->getBlock($blockName);
91  if (is_object($blockInstance)) {
92  $data[$blockName] = $blockInstance;
93  }
94  }
95 
96  return $data;
97  }
98 }
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\Translate\InlineInterface $translateInline, Json $jsonSerializer=null, Base64Json $base64jsonSerializer=null, LayoutCacheKeyInterface $layoutCacheKey=null)
Definition: Block.php:50