/** * Constructor * * @param TemplateContext $context * @param UiComponentInterface $component * @param BlockFactory $blockWrapperFactory * @param array $data */ public function __construct(TemplateContext $context, UiComponentInterface $component, BlockFactory $blockWrapperFactory, array $data = []) { $this->component = $component; $this->blockWrapperFactory = $blockWrapperFactory; $this->setNameInLayout($this->component->getName()); parent::__construct($context, $data); }
/** * Add children data * * @param array $topNode * @param UiComponentInterface $component * @param string $componentType * @return void */ protected function addChildren(array &$topNode, UiComponentInterface $component, $componentType) { $childrenNode = []; $childComponents = $component->getChildComponents(); if (!empty($childComponents)) { /** @var UiComponentInterface $child */ foreach ($childComponents as $child) { if ($child instanceof DataSourceInterface) { continue; } self::addChildren($childrenNode, $child, $child->getComponentName()); } } $config = $component->getConfiguration(); if (is_string($config)) { $topNode[$config] = $config; } else { $nodeData = ['type' => $componentType, 'name' => $component->getName()]; if (!empty($childrenNode)) { $nodeData['children'] = $childrenNode; } if (isset($config['dataScope'])) { $nodeData['dataScope'] = $config['dataScope']; unset($config['dataScope']); } if (!empty($config)) { $nodeData['config'] = $config; } $topNode[$component->getName()] = $nodeData; } }
/** * @param UiComponentInterface $view * @return string */ protected function getDataXml(UiComponentInterface $view) { $result = ['configuration' => $view->getRenderContext()->getStorage()->getComponentsData($view->getName())->getData(), 'data' => []]; foreach ($view->getRenderContext()->getStorage()->getData($view->getName()) as $key => $value) { if (is_object($value)) { if (method_exists($value, 'toXml')) { $result['data'][$key] = $value->toXml(); } else { $result['data'][$key] = $this->objectToXml($value); } } else { $result['data'][$key] = $value; } } return $this->generator->arrayToXml($result); }
/** * @inheritDoc */ public function update(UiComponentInterface $component) { if ($component instanceof ColumnInterface) { $filterType = $component->getData('config/filter'); if (is_array($filterType)) { $filterType = $filterType['filterType']; } if (!$filterType) { return; } if (isset($this->filterMap[$filterType])) { $filterComponent = $this->uiComponentFactory->create($component->getName(), $this->filterMap[$filterType], ['context' => $this->getContext()]); $filterComponent->setData('config', $component->getConfiguration()); $filterComponent->prepare(); $this->addComponent($component->getName(), $filterComponent); } } }
/** * Returns columns list * * @param UiComponentInterface $component * @return UiComponentInterface[] */ protected function getColumns(UiComponentInterface $component) { if (!isset($this->columns[$component->getName()])) { $columns = $this->getColumnsComponent($component); foreach ($columns->getChildComponents() as $column) { $this->columns[$component->getName()][$column->getName()] = $column; } } return $this->columns[$component->getName()]; }
/** * Returns columns list * * @param UiComponentInterface $component * @return UiComponentInterface[] */ protected function getColumns(UiComponentInterface $component) { if (!isset($this->columns[$component->getName()])) { $columns = $this->getColumnsComponent($component); foreach ($columns->getChildComponents() as $column) { if ($column->getData('config/label') && $column->getData('config/dataType') !== 'actions') { $this->columns[$component->getName()][$column->getName()] = $column; } } } return $this->columns[$component->getName()]; }
/** * Create button container * * @param string $key * @param UiComponentInterface $view * @return Container */ protected function createContainer($key, UiComponentInterface $view) { $container = $this->context->getPageLayout()->createBlock('Magento\\Ui\\Component\\Control\\Container', 'container-' . $view->getName() . '-' . $key, ['data' => ['button_item' => $this->items[$key], 'context' => $view]]); return $container; }
/** * Create child of form * * @param UiComponentInterface $childComponent * @param string $name * @return UiComponentInterface * @throws \Magento\Framework\Exception\LocalizedException */ protected function createChildFormComponent(UiComponentInterface $childComponent, $name) { $panelComponent = $this->uiComponentFactory->create($name, $this->getConfig(self::CONFIG_PANEL_COMPONENT), ['context' => $this->component->getContext(), 'components' => [$childComponent->getName() => $childComponent]]); $panelComponent->prepare(); $this->component->addComponent($name, $panelComponent); return $panelComponent; }
/** * Update field data * * @param array $fieldData * @param UiComponentInterface $component * @return void */ protected function updateField(array $fieldData, UiComponentInterface $component) { $config = $component->getData('config'); // XML data configuration override configuration coming from the DB $config = array_replace_recursive($fieldData, $config); $config = $this->updateDataScope($config, $component->getName()); $component->setData('config', $config); }
/** * To prepare the structure of child components * * @param UiComponentInterface $component * @param string $parentName * @return array */ protected function prepareChildComponents(UiComponentInterface $component, $parentName) { $name = $component->getName(); $childComponents = $component->getChildComponents(); $childrenStructure = []; foreach ($childComponents as $childName => $child) { $isVisible = $child->getData('config/visible'); if ($isVisible !== null && $isVisible == 0) { continue; } /** * @var UiComponentInterface $childComponent * @var array $childStructure */ list($childComponent, $childStructure) = $this->prepareChildComponents($child, $component->getName()); $childrenStructure = array_merge($childrenStructure, $childStructure); $component->addComponent($childName, $childComponent); } $structure = [$name => ['type' => $component->getComponentName(), 'name' => $component->getName(), 'children' => $childrenStructure]]; list($config, $dataScope) = $this->prepareConfig((array) $component->getConfiguration(), $name, $parentName); if ($dataScope !== false) { $structure[$name]['dataScope'] = $dataScope; } $structure[$name]['config'] = $config; return [$component, $structure]; }
/** * Render data * * @param UiComponentInterface $view * @param string $template * @return string */ public function render(UiComponentInterface $view, $template = '') { return $view->getRenderContext()->getConfigBuilder()->toJson($view->getRenderContext()->getStorage(), $view->getName()); }