Example #1
0
 /**
  * Call prepare method in the component UI
  *
  * @param UiComponentInterface $component
  * @return void
  */
 protected function prepareComponent(UiComponentInterface $component)
 {
     foreach ($component->getChildComponents() as $child) {
         $this->prepareComponent($child);
     }
     $component->prepare();
 }
 /**
  * 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;
             }
             if ($child instanceof BlockWrapperInterface) {
                 $this->addWrappedBlock($child, $childrenNode);
                 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;
     }
 }
 /**
  * Returns Columns component
  *
  * @param UiComponentInterface $component
  * @return UiComponentInterface
  * @throws \Exception
  */
 protected function getColumnsComponent(UiComponentInterface $component)
 {
     foreach ($component->getChildComponents() as $childComponent) {
         if ($childComponent instanceof Columns) {
             return $childComponent;
         }
     }
     throw new \Exception('No columns found');
 }
Example #4
0
 /**
  * Prepare component configuration
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepare()
 {
     $formElement = $this->getData('config/formElement');
     if (null === $formElement) {
         throw new LocalizedException(__('The configuration parameter "formElement" is a required for "%1" field.', $this->getName()));
     }
     // Create of wrapped component
     $this->wrappedComponent = $this->uiComponentFactory->create($this->getName(), $formElement, array_merge(['context' => $this->getContext()], (array) $this->getData()));
     $this->wrappedComponent->setData('config', array_replace_recursive((array) $this->wrappedComponent->getData('config'), (array) $this->getData('config')));
     $this->wrappedComponent->prepare();
     $this->components = $this->wrappedComponent->getChildComponents();
     // Merge JS configuration with wrapped component configuration
     $wrappedComponentConfig = $this->getJsConfig($this->wrappedComponent);
     $jsConfig = array_replace_recursive($wrappedComponentConfig, $this->getJsConfig($this));
     $jsConfig['extends'] = $this->wrappedComponent->getComponentName();
     $this->setData('js_config', $jsConfig);
     $this->setData('config', $this->wrappedComponent->getData('config'));
     parent::prepare();
 }
Example #5
0
 /**
  * Call prepare method in the component UI
  *
  * @param UiComponentInterface $component
  * @return void
  */
 protected function prepareComponent(UiComponentInterface $component)
 {
     $childComponents = $component->getChildComponents();
     if (!empty($childComponents)) {
         foreach ($childComponents as $child) {
             $this->prepareComponent($child);
         }
     }
     $component->prepare();
 }
Example #6
0
 /**
  * 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];
 }
Example #7
0
 /**
  * Call `prepareData` method of all the components
  *
  * @param array $data
  * @param UiComponentInterface $component
  * @return void
  */
 protected function prepareDataSource(array &$data, UiComponentInterface $component)
 {
     $childComponents = $component->getChildComponents();
     if (!empty($childComponents)) {
         foreach ($childComponents as $child) {
             $this->prepareDataSource($data, $child);
         }
     }
     $data = $component->prepareDataSource($data);
 }