Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Block Class Reference
Inheritance diagram for Block:
Action AbstractAction ActionInterface Esi Render

Public Member Functions

 __construct (\Magento\Framework\App\Action\Context $context, \Magento\Framework\Translate\InlineInterface $translateInline, Json $jsonSerializer=null, Base64Json $base64jsonSerializer=null, LayoutCacheKeyInterface $layoutCacheKey=null)
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Protected Member Functions

 _getBlocks ()
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $translateInline
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Additional Inherited Members

- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 

Detailed Description

Definition at line 14 of file Block.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Action\Context  $context,
\Magento\Framework\Translate\InlineInterface  $translateInline,
Json  $jsonSerializer = null,
Base64Json  $base64jsonSerializer = null,
LayoutCacheKeyInterface  $layoutCacheKey = null 
)
Parameters
\Magento\Framework\App\Action\Context$context
\Magento\Framework\Translate\InlineInterface$translateInline
Json$jsonSerializer
Base64Json$base64jsonSerializer
LayoutCacheKeyInterface$layoutCacheKey

Definition at line 50 of file Block.php.

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  }

Member Function Documentation

◆ _getBlocks()

_getBlocks ( )
protected

Get blocks from layout by handles

Returns
array [\Element\BlockInterface]

Definition at line 72 of file Block.php.

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  }

Field Documentation

◆ $translateInline

$translateInline
protected

Definition at line 19 of file Block.php.


The documentation for this class was generated from the following file: