예제 #1
0
 /**
  * Get attributes meta
  *
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function map($attribute)
 {
     foreach ($this->metaPropertiesMap as $metaName => $methodName) {
         $value = $attribute->{$methodName}();
         $meta[$metaName] = $value;
         if ('getFrontendInput' === $methodName) {
             $meta['formElement'] = isset($this->formElementMap[$value]) ? $this->formElementMap[$value] : $value;
         }
     }
     if ($attribute->usesSource()) {
         $meta['options'] = $attribute->getSource()->getAllOptions();
     }
     $rules = [];
     if (isset($meta['required']) && $meta['required'] == 1) {
         $rules['required-entry'] = true;
     }
     foreach ($attribute->getValidateRules() as $name => $value) {
         if (isset($this->validationRules[$name][$value])) {
             $rules = array_merge($rules, $this->validationRules[$name][$value]);
         } else {
             $rules[$name] = $value;
         }
     }
     $meta['validation'] = $rules;
     return $meta;
 }
예제 #2
0
 /**
  * Get attribute type based on its backend model.
  * 
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @param string $serviceClass
  * @param $serviceBackendModelDataInterfaceMap array
  * @return string|null
  */
 public function getType($attribute, $serviceClass, $serviceBackendModelDataInterfaceMap)
 {
     $backendModel = $attribute->getBackendModel();
     //If empty backend model, check if it can be derived
     if (empty($backendModel)) {
         $backendModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->stringUtility->upperCaseWords($attribute->getFrontendInput()));
         $backendModel = class_exists($backendModelClass) ? $backendModelClass : null;
     }
     $dataInterface = isset($serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null;
     return $dataInterface;
 }
예제 #3
0
 /**
  * Get attribute type based on its frontend input and backend type.
  *
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @return string
  */
 public function getType($attribute)
 {
     if (in_array($attribute->getAttributeCode(), $this->anyTypeAttributes)) {
         return TypeProcessor::NORMALIZED_ANY_TYPE;
     }
     $frontendInput = $attribute->getFrontendInput();
     $backendType = $attribute->getBackendType();
     $backendTypeMap = ['static' => TypeProcessor::NORMALIZED_ANY_TYPE, 'int' => TypeProcessor::NORMALIZED_INT_TYPE, 'text' => TypeProcessor::NORMALIZED_STRING_TYPE, 'varchar' => TypeProcessor::NORMALIZED_STRING_TYPE, 'datetime' => TypeProcessor::NORMALIZED_STRING_TYPE, 'decimal' => TypeProcessor::NORMALIZED_DOUBLE_TYPE];
     $arrayFrontendInputs = ['multiselect'];
     $type = $backendTypeMap[$backendType];
     if (in_array($frontendInput, $arrayFrontendInputs)) {
         $type .= '[]';
     }
     return $type;
 }
예제 #4
0
 /**
  * Process attributes by frontend input type
  *
  * @param AttributeInterface $attribute
  * @param array $meta
  * @return array
  */
 private function processFrontendInput(AttributeInterface $attribute, array &$meta)
 {
     $code = $attribute->getAttributeCode();
     if ($attribute->getFrontendInput() === 'boolean') {
         $meta[$code]['arguments']['data']['config']['prefer'] = 'toggle';
         $meta[$code]['arguments']['data']['config']['valueMap'] = ['true' => '1', 'false' => '0'];
     }
 }
예제 #5
0
 /**
  * @param \Magento\Eav\Api\Data\AttributeInterface $attribute
  * @param int $optionId
  * @throws NoSuchEntityException
  * @return void
  */
 protected function validateOption($attribute, $optionId)
 {
     if (!$attribute->getSource()->getOptionText($optionId)) {
         throw new NoSuchEntityException(__('Attribute %1 does not contain option with Id %2', $attribute->getAttributeCode(), $optionId));
     }
 }