Ejemplo n.º 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;
 }
Ejemplo n.º 2
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));
     }
 }