예제 #1
0
 /**
  * Get attributes meta
  *
  * @param Type $entityType
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function getAttributesMeta(Type $entityType)
 {
     $meta = [];
     $attributes = $entityType->getAttributeCollection();
     /* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     foreach ($attributes as $attribute) {
         $code = $attribute->getAttributeCode();
         // use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
         foreach ($this->metaProperties as $metaName => $origName) {
             $value = $attribute->getDataUsingMethod($origName);
             $meta[$code][$metaName] = $metaName === 'label' ? __($value) : $value;
             if ('frontend_input' === $origName) {
                 $meta[$code]['formElement'] = isset($this->formElement[$value]) ? $this->formElement[$value] : $value;
             }
             if ($attribute->usesSource()) {
                 $meta[$code]['options'] = $attribute->getSource()->getAllOptions();
             }
         }
         $rules = $this->eavValidationRules->build($attribute, $meta[$code]);
         if (!empty($rules)) {
             $meta[$code]['validation'] = $rules;
         }
     }
     return $meta;
 }
 /**
  * Get attributes meta
  *
  * @param Type $entityType
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getAttributesMeta(Type $entityType)
 {
     $meta = [];
     $attributes = $entityType->getAttributeCollection();
     /* @var EavAttribute $attribute */
     foreach ($attributes as $attribute) {
         $code = $attribute->getAttributeCode();
         // use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
         foreach ($this->metaProperties as $metaName => $origName) {
             $value = $attribute->getDataUsingMethod($origName);
             $meta[$code][$metaName] = $value;
             if ('frontend_input' === $origName) {
                 $meta[$code]['formElement'] = isset($this->formElement[$value]) ? $this->formElement[$value] : $value;
             }
             if ($attribute->usesSource()) {
                 $meta[$code]['options'] = $attribute->getSource()->getAllOptions();
             }
         }
         $rules = $this->eavValidationRules->build($attribute, $meta[$code]);
         if (!empty($rules)) {
             $meta[$code]['validation'] = $rules;
         }
         $meta[$code]['scopeLabel'] = $this->getScopeLabel($attribute);
         $meta[$code]['componentType'] = Field::NAME;
     }
     $result = [];
     foreach ($meta as $key => $item) {
         $result[$key] = $item;
         $result[$key]['sortOrder'] = 0;
     }
     $result = $this->getDefaultMetaData($result);
     return $result;
 }