Example #1
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();
 }
 /**
  * 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;
 }
 /**
  * Update component data
  *
  * @param array $componentData
  * @param UiComponentInterface $component
  * @return $this
  */
 protected function updateComponent(array $componentData, UiComponentInterface $component)
 {
     $config = $component->getData('config');
     // XML data configuration override configuration coming from the DB
     $config = array_replace_recursive($componentData, $config);
     $component->setData('config', $config);
     return $this;
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
 /**
  * Add options to component
  *
  * @param UiComponentInterface $component
  * @param array $attributeData
  * @return void
  */
 public function addOptions(UiComponentInterface $component, array $attributeData)
 {
     $config = $component->getData('config');
     if (count($attributeData[AttributeMetadata::OPTIONS]) && !isset($config[AttributeMetadata::OPTIONS])) {
         $component->setData('config', array_merge($config, [AttributeMetadata::OPTIONS => $attributeData[AttributeMetadata::OPTIONS]]));
     }
 }