/** * Creates UI Component object based on scheduled data and add it to the layout * * @param ReaderContext $readerContext * @param GeneratorContext $generatorContext * @return $this */ public function process(ReaderContext $readerContext, GeneratorContext $generatorContext) { $scheduledStructure = $readerContext->getScheduledStructure(); $scheduledElements = $scheduledStructure->getElements(); if (!$scheduledElements) { return $this; } $structure = $generatorContext->getStructure(); $layout = $generatorContext->getLayout(); // Instantiate blocks and collect all actions data /** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */ $blocks = []; foreach ($scheduledElements as $elementName => $element) { list(, $data) = $element; $block = $this->generateComponent($structure, $elementName, $data, $layout); $blocks[$elementName] = $block; $layout->setBlock($elementName, $block); $scheduledStructure->unsetElement($elementName); } return $this; }
/** * Creates block object based on data and add it to the layout * * @param Layout\Reader\Context $readerContext * @param Context $generatorContext * @return $this */ public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext) { $scheduledStructure = $readerContext->getScheduledStructure(); $layout = $generatorContext->getLayout(); $structure = $generatorContext->getStructure(); /** @var $blocks \Magento\Framework\View\Element\AbstractBlock[] */ $blocks = []; $blockActions = []; // Instantiate blocks and collect all actions data foreach ($scheduledStructure->getElements() as $elementName => $element) { list($type, $data) = $element; if ($type === self::TYPE) { $block = $this->generateBlock($scheduledStructure, $structure, $elementName); $blocks[$elementName] = $block; $layout->setBlock($elementName, $block); if (!empty($data['actions'])) { $blockActions[$elementName] = $data['actions']; } } } // Set layout instance to all generated block (trigger _prepareLayout method) foreach ($blocks as $elementName => $block) { $block->setLayout($layout); $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]); $scheduledStructure->unsetElement($elementName); } // Run all actions after layout initialization foreach ($blockActions as $elementName => $actions) { foreach ($actions as $action) { list($methodName, $actionArguments, $configPath, $scopeType) = $action; if (empty($configPath) || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope())) { $this->generateAction($blocks[$elementName], $methodName, $actionArguments); } } } return $this; }