/**
  * Create AttributeMetadata Data object from the Attribute Model
  *
  * @param \Magento\Customer\Model\Attribute $attribute
  * @return \Magento\Customer\Api\Data\AttributeMetadataInterface
  */
 public function createMetadataAttribute($attribute)
 {
     $options = [];
     if ($attribute->usesSource()) {
         foreach ($attribute->getSource()->getAllOptions() as $option) {
             $optionDataObject = $this->optionFactory->create();
             if (!is_array($option['value'])) {
                 $optionDataObject->setValue($option['value']);
             } else {
                 $optionArray = [];
                 foreach ($option['value'] as $optionArrayValues) {
                     $optionObject = $this->optionFactory->create();
                     $this->dataObjectHelper->populateWithArray($optionObject, $optionArrayValues, '\\Magento\\Customer\\Api\\Data\\OptionInterface');
                     $optionArray[] = $optionObject;
                 }
                 $optionDataObject->setOptions($optionArray);
             }
             $optionDataObject->setLabel($option['label']);
             $options[] = $optionDataObject;
         }
     }
     $validationRules = [];
     foreach ($attribute->getValidateRules() as $name => $value) {
         $validationRule = $this->validationRuleFactory->create()->setName($name)->setValue($value);
         $validationRules[] = $validationRule;
     }
     return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setIsVisible((bool) $attribute->getIsVisible())->setIsRequired((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())->setIsUsedInGrid($attribute->getIsUsedInGrid())->setIsVisibleInGrid($attribute->getIsVisibleInGrid())->setIsFilterableInGrid($attribute->getIsFilterableInGrid())->setIsSearchableInGrid($attribute->getIsSearchableInGrid());
 }
 /**
  * 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();
 }