/** * Create AttributeMetadata Data object from the Attribute Model * * @param \Magento\Customer\Model\Attribute $attribute * @return AttributeMetadata */ public function createMetadataAttribute($attribute) { $options = []; if ($attribute->usesSource()) { foreach ($attribute->getSource()->getAllOptions() as $option) { $options[] = $this->_optionBuilder->setLabel($option['label'])->setValue($option['value'])->create(); } } $validationRules = []; foreach ($attribute->getValidateRules() as $name => $value) { $validationRules[] = $this->_validationRuleBuilder->setName($name)->setValue($value)->create(); } $this->_attributeMetadataBuilder->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setVisible((bool) $attribute->getIsVisible())->setRequired((bool) $attribute->getIsRequired())->setMultilineCount((int) $attribute->getMultilineCount())->setDataModel((string) $attribute->getDataModel())->setOptions($options)->setFrontendClass($attribute->getFrontend()->getClass())->setFrontendLabel($attribute->getFrontendLabel())->setNote((string) $attribute->getNote())->setIsSystem((bool) $attribute->getIsSystem())->setIsUserDefined((bool) $attribute->getIsUserDefined())->setBackendType($attribute->getBackendType())->setSortOrder((int) $attribute->getSortOrder()); return $this->_attributeMetadataBuilder->create(); }
public function testCreate() { $attributeMetadata = $this->_builder->create(); $this->assertInstanceOf('\\Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', $attributeMetadata); $this->assertEquals(array(), $attributeMetadata->getOptions()); }