layoutHelper = $helper; $this->conditionReader = $conditionReader; $this->uiConfigFactory = $uiConfigFactory; $this->readerPool = $readerPool; } /** * {@inheritdoc} */ public function getSupportedNodes() { return [self::TYPE_UI_COMPONENT]; } /** * {@inheritdoc} */ public function interpret(Context $readerContext, Element $currentElement) { $attributes = $this->getAttributes($currentElement); $scheduledStructure = $readerContext->getScheduledStructure(); $referenceName = $this->layoutHelper->scheduleStructure( $scheduledStructure, $currentElement, $currentElement->getParent(), ['attributes' => $attributes] ); $attributes = array_merge( $attributes, ['visibilityConditions' => $this->conditionReader->parseConditions($currentElement)] ); $scheduledStructure->setStructureElementData($referenceName, ['attributes' => $attributes]); $elements = []; $config = $this->uiConfigFactory->create(['componentName' => $referenceName])->get($referenceName); $this->getLayoutElementsFromUiConfiguration([$referenceName => $config], $elements); foreach ($elements as $layoutElement) { $layoutElement = simplexml_load_string( $layoutElement, Element::class ); $this->readerPool->interpret($readerContext, $layoutElement); } return $this; } /** * Find layout elements in UI configuration for correct layout generation * * @param array $config * @param array $elements * @return void */ private function getLayoutElementsFromUiConfiguration(array $config, array &$elements = []) { foreach ($config as $data) { if (isset($data['arguments']['block']['layout'])) { $elements[] = $data['arguments']['block']['layout']; } if (isset($data['children']) && !empty($data['children'])) { $this->getLayoutElementsFromUiConfiguration($data['children'], $elements); } } } /** * Get ui component attributes * * @param Element $element * @return array */ protected function getAttributes(Element $element) { $attributes = []; foreach ($this->attributes as $attributeName) { $attributes[$attributeName] = (string)$element->getAttribute($attributeName); } return $attributes; } }