Beispiel #1
0
 /**
  * Returns component by namespace
  *
  * @return UiComponentInterface
  * @throws LocalizedException
  */
 public function getComponent()
 {
     $namespace = $this->request->getParam('namespace');
     if (!isset($this->components[$namespace])) {
         $this->components[$namespace] = $this->factory->create($namespace);
     }
     return $this->components[$namespace];
 }
Beispiel #2
0
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, array $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['label' => __($attribute->getDefaultFrontendLabel()), 'dataType' => $this->getDataType($attribute), 'sorting' => 'asc', 'align' => 'left', 'add_field' => true, 'visible' => $attribute->getIsVisibleInGrid()], $config);
     if ($attribute->usesSource()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
     }
     $arguments = ['data' => ['js_config' => ['component' => $this->getJsComponent($config['dataType'])], 'config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, 'column', $arguments);
 }
Beispiel #3
0
 /**
  * @param array $attributeData
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create(array $attributeData, $context)
 {
     $config = ['dataScope' => $attributeData[AttributeMetadata::ATTRIBUTE_CODE], 'label' => __($attributeData[AttributeMetadata::FRONTEND_LABEL])];
     if ($attributeData[AttributeMetadata::OPTIONS]) {
         $config['options'] = $attributeData[AttributeMetadata::OPTIONS];
         $config['caption'] = __('Select...');
     }
     $arguments = ['data' => ['config' => $config], 'context' => $context];
     return $this->componentFactory->create($attributeData[AttributeMetadata::ATTRIBUTE_CODE], $this->getFilterType($attributeData[AttributeMetadata::FRONTEND_INPUT]), $arguments);
 }
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, array $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['label' => __($attribute->getDefaultFrontendLabel()), 'dataType' => $this->getDataType($attribute), 'add_field' => true, 'visible' => $attribute->getIsVisibleInGrid(), 'filter' => $attribute->getIsFilterableInGrid() ? $this->getFilterType($attribute->getFrontendInput()) : null], $config);
     if ($attribute->usesSource()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
     }
     $config['component'] = $this->getJsComponent($config['dataType']);
     $arguments = ['data' => ['config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, 'column', $arguments);
 }
 /**
  * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create($attribute, $context, $config = [])
 {
     $columnName = $attribute->getAttributeCode();
     $config = array_merge(['dataScope' => $columnName, 'label' => __($attribute->getDefaultFrontendLabel())], $config);
     if ($attribute->usesSource() && $attribute->getSourceModel()) {
         $config['options'] = $attribute->getSource()->getAllOptions();
         $config['caption'] = __('Select...');
     }
     $arguments = ['data' => ['config' => $config], 'context' => $context];
     return $this->componentFactory->create($columnName, $this->getFilterType($attribute), $arguments);
 }
Beispiel #6
0
 /**
  * Prepare component configuration
  *
  * @return void
  */
 public function prepare()
 {
     parent::prepare();
     $dataType = $this->getData('config/dataType');
     $wrappedComponentConfig = [];
     if ($dataType) {
         $this->wrappedComponent = $this->uiComponentFactory->create($this->getName(), $dataType, array_merge(['context' => $this->getContext()], (array) $this->getData()));
         $this->wrappedComponent->prepare();
         $wrappedComponentConfig = $this->getConfiguration($this->wrappedComponent);
     }
     $this->applySorting();
     $jsConfig = array_replace_recursive($wrappedComponentConfig, $this->getConfiguration($this));
     $this->getContext()->addComponentDefinition($this->getComponentName(), $jsConfig);
 }
 /**
  * @param array $attributeData
  * @param string $columnName
  * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
  * @param array $config
  * @return \Magento\Ui\Component\Listing\Columns\ColumnInterface
  */
 public function create(array $attributeData, $columnName, $context, array $config = [])
 {
     $config = array_merge(['label' => __($attributeData[AttributeMetadata::FRONTEND_LABEL]), 'dataType' => $this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT]), 'align' => 'left', 'visible' => (bool) $attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID]], $config);
     if (count($attributeData[AttributeMetadata::OPTIONS]) && !isset($config[AttributeMetadata::OPTIONS])) {
         $config[AttributeMetadata::OPTIONS] = $attributeData[AttributeMetadata::OPTIONS];
     }
     if ($attributeData[AttributeMetadata::OPTIONS]) {
         $config['options'] = $attributeData[AttributeMetadata::OPTIONS];
     }
     $arguments = ['data' => ['js_config' => ['component' => $this->getJsComponent($config['dataType'])], 'config' => $config], 'context' => $context];
     $column = $this->componentFactory->create($columnName, 'column', $arguments);
     $this->inlineEditUpdater->applyEditing($column, $attributeData[AttributeMetadata::FRONTEND_INPUT], $attributeData[AttributeMetadata::VALIDATION_RULES], $attributeData[AttributeMetadata::REQUIRED]);
     return $column;
 }
Beispiel #8
0
 /**
  * Prepare component configuration
  *
  * @return void
  */
 public function prepare()
 {
     $dataType = $this->getData('config/dataType');
     if ($dataType) {
         $this->wrappedComponent = $this->uiComponentFactory->create($this->getName(), $dataType, array_merge(['context' => $this->getContext()], (array) $this->getData()));
         $this->wrappedComponent->prepare();
         $wrappedComponentConfig = $this->getJsConfig($this->wrappedComponent);
         // Merge JS configuration with wrapped component configuration
         $jsConfig = array_replace_recursive($wrappedComponentConfig, $this->getJsConfig($this));
         $this->setData('js_config', $jsConfig);
         $this->setData('config', array_replace_recursive((array) $this->wrappedComponent->getData('config'), (array) $this->getData('config')));
     }
     $this->applySorting();
     parent::prepare();
 }
Beispiel #9
0
 /**
  * Prepare component configuration
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepare()
 {
     parent::prepare();
     $formElement = $this->getData('config/formElement');
     if (null === $formElement) {
         throw new LocalizedException(__('The configuration parameter "formElement" is a required for "' . $this->getName() . '" field.'));
     }
     // Create of wrapped component
     $this->wrappedComponent = $this->uiComponentFactory->create($this->getName(), $formElement, array_merge(['context' => $this->getContext()], (array) $this->getData()));
     $this->wrappedComponent->prepare();
     // To prepare the component configuration
     $wrappedComponentConfig = $this->getConfiguration($this->wrappedComponent);
     $jsConfig = array_replace_recursive($wrappedComponentConfig, $this->getConfiguration($this, $this->wrappedComponent->getComponentName()));
     $this->getContext()->addComponentDefinition($this->getComponentName(), $jsConfig);
 }
 /**
  * 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;
 }
 /**
  * Prepare component configuration
  *
  * @return void
  */
 public function prepare()
 {
     $size = abs((int) $this->getData('config/size'));
     $validation = [$this->getData('config/validation')];
     while ($size--) {
         $identifier = $this->getName() . '_' . $size;
         $arguments = ['data' => ['name' => $identifier, 'config' => ['dataScope' => $size, 'dataType' => static::DATA_TYPE, 'formElement' => static::FORM_ELEMENT, 'sortOrder' => $size]]];
         if (!empty($validation[$size])) {
             $arguments['data']['config']['validation'] = $validation[$size];
         }
         $component = $this->uiComponentFactory->create($identifier, Field::NAME, $arguments);
         $component->prepare();
         $this->components[$identifier] = $component;
     }
     parent::prepare();
 }
Beispiel #12
0
 /**
  * Create tab component
  *
  * @param UiComponentInterface $childComponent
  * @param string $name
  * @return UiComponentInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function createTabComponent(UiComponentInterface $childComponent, $name)
 {
     $tabComponent = $this->uiComponentFactory->create($name, 'tab', ['context' => $this->component->getContext(), 'components' => [$childComponent->getName() => $childComponent]]);
     $tabComponent->prepare();
     $this->component->addComponent($name, $tabComponent);
     return $tabComponent;
 }
Beispiel #13
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 "' . $this->getName() . '" field.'));
     }
     // Create of wrapped component
     $this->wrappedComponent = $this->uiComponentFactory->create($this->getName(), $formElement, array_merge(['context' => $this->getContext()], (array) $this->getData()));
     $this->wrappedComponent->prepare();
     // 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', array_replace_recursive((array) $this->wrappedComponent->getData('config'), (array) $this->getData('config')));
     parent::prepare();
 }
Beispiel #14
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);
         }
     }
 }
Beispiel #15
0
 /**
  * Create component object
  *
  * @param Structure $structure
  * @param string $elementName
  * @param string $data
  * @param LayoutInterface $layout
  * @return ContainerInterface
  */
 protected function generateComponent(Structure $structure, $elementName, $data, LayoutInterface $layout)
 {
     $attributes = $data['attributes'];
     if (!empty($attributes['group'])) {
         $structure->addToParentGroup($elementName, $attributes['group']);
     }
     $context = $this->contextFactory->create(['namespace' => $elementName, 'pageLayout' => $layout]);
     $component = $this->uiComponentFactory->create($elementName, null, ['context' => $context]);
     $this->prepareComponent($component);
     /** @var ContainerInterface $blockContainer */
     $blockContainer = $this->blockFactory->createBlock(static::CONTAINER, ['component' => $component]);
     return $blockContainer;
 }