Exemplo n.º 1
0
 /**
  * Initial meta setup
  *
  * @param ProductAttributeInterface $attribute
  * @param string $groupCode
  * @param int $sortOrder
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @api
  */
 public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 {
     $configPath = ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
     $meta = $this->arrayManager->set($configPath, [], ['dataType' => $attribute->getFrontendInput(), 'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()), 'visible' => $attribute->getIsVisible(), 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote(), 'default' => $attribute->getDefaultValue(), 'label' => $attribute->getDefaultFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'source' => $groupCode, 'scopeLabel' => $this->getScopeLabel($attribute), 'globalScope' => $this->isScopeGlobal($attribute), 'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER]);
     // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
     $attributeModel = $this->getAttributeModel($attribute);
     if ($attributeModel->usesSource()) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['options' => $attributeModel->getSource()->getAllOptions()]);
     }
     if ($this->canDisplayUseDefault($attribute)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['service' => ['template' => 'ui/form/element/helper/service']]);
     }
     if (!$this->arrayManager->exists($configPath . '/componentType', $meta)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['componentType' => Field::NAME]);
     }
     if (in_array($attribute->getAttributeCode(), $this->attributesToDisable)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['disabled' => true]);
     }
     // TODO: getAttributeModel() should not be used when MAGETWO-48284 is complete
     $childData = $this->arrayManager->get($configPath, $meta, []);
     if ($rules = $this->catalogEavValidationRules->build($this->getAttributeModel($attribute), $childData)) {
         $meta = $this->arrayManager->merge($configPath, $meta, ['validation' => $rules]);
     }
     $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
     switch ($attribute->getFrontendInput()) {
         case 'boolean':
             $meta = $this->customizeCheckbox($attribute, $meta);
             break;
         case 'textarea':
             $meta = $this->customizeWysiwyg($attribute, $meta);
             break;
         case 'price':
             $meta = $this->customizePriceAttribute($attribute, $meta);
             break;
         case 'gallery':
             // Gallery attribute is being handled by "Images And Videos" section
             $meta = [];
             break;
     }
     return $meta;
 }
Exemplo n.º 2
0
 /**
  * Initial meta setup
  *
  * @param ProductAttributeInterface $attribute
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function setupMetaProperties(ProductAttributeInterface $attribute)
 {
     $meta = ['arguments' => ['data' => ['config' => ['dataType' => $attribute->getFrontendInput(), 'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()), 'visible' => $attribute->getIsVisible(), 'required' => $attribute->getIsRequired(), 'notice' => $attribute->getNote(), 'default' => $attribute->getDefaultValue(), 'label' => __('%1', $attribute->getDefaultFrontendLabel())]]]];
     foreach ($meta as $key => $value) {
         if ($value === null) {
             unset($meta[$key]);
         }
     }
     // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
     $attributeModel = $this->getAttributeModel($attribute);
     if ($attributeModel->usesSource()) {
         $meta['arguments']['data']['config']['options'] = $attributeModel->getSource()->getAllOptions();
     }
     $meta = $this->addWysiwyg($attribute, $meta);
     $meta = $this->customizeCheckbox($attribute, $meta);
     $meta = $this->customizePriceAttribute($attribute, $meta);
     $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
     return $meta;
 }