Example #1
0
 /**
  * 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;
     }
 }
Example #2
0
 /**
  * @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);
         }
     }
 }
 /**
  * Add editor config
  *
  * @param UiComponentInterface $column
  * @param string $frontendInput
  * @param array $validationRules
  * @param bool|false $isRequired
  * @return UiComponentInterface
  */
 public function applyEditing(UiComponentInterface $column, $frontendInput, array $validationRules, $isRequired = false)
 {
     if (in_array($frontendInput, $this->editableFields)) {
         $config = $column->getConfiguration();
         $editorType = $config['dataType'];
         if (isset($config['editor']) && is_string($config['editor'])) {
             $editorType = $config['editor'];
         }
         if (!(isset($config['editor']) && isset($config['editor']['editorType']))) {
             $config['editor'] = ['editorType' => $editorType];
         }
         $validationRules = $this->validationRules->getValidationRules($isRequired, $validationRules);
         if (!empty($config['editor']['validation'])) {
             $validationRules = array_merge($config['editor']['validation'], $validationRules);
         }
         $config['editor']['validation'] = $validationRules;
         $column->setData('config', $config);
     }
     return $column;
 }
Example #4
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];
 }