/**
  * Initialize dependencies.
  *
  * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory
  * @param AttributeValueBuilder $valueBuilder
  * @param MetadataServiceInterface $metadataService
  */
 public function __construct(\Magento\Framework\Service\Data\ObjectFactory $objectFactory, AttributeValueBuilder $valueBuilder, MetadataServiceInterface $metadataService)
 {
     parent::__construct($objectFactory, $valueBuilder);
     $this->metadataService = $metadataService;
 }
 /**
  * {@inheritdoc}
  */
 public function getCustomAttributesCodes()
 {
     return array_merge($this->customAttributeCodes, parent::getCustomAttributesCodes());
 }
 /**
  * {@inheritdoc}
  */
 protected function _setDataValues(array $data)
 {
     if (array_key_exists(Address::KEY_REGION, $data)) {
         if (!is_array($data[Address::KEY_REGION])) {
             // Region data has been submitted as individual keys of Address object. Let's extract it.
             $regionData = array();
             foreach (array(Region::KEY_REGION, Region::KEY_REGION_CODE, Region::KEY_REGION_ID) as $attrCode) {
                 if (isset($data[$attrCode])) {
                     $regionData[$attrCode] = $data[$attrCode];
                 }
             }
         } else {
             $regionData = $data[Address::KEY_REGION];
         }
         $data[Address::KEY_REGION] = $this->_regionBuilder->populateWithArray($regionData)->create();
     }
     return parent::_setDataValues($data);
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _setDataValues(array $data)
 {
     if (array_key_exists(AttributeMetadata::OPTIONS, $data)) {
         $options = array();
         if (is_array($data[AttributeMetadata::OPTIONS])) {
             foreach ($data[AttributeMetadata::OPTIONS] as $key => $option) {
                 $options[$key] = $this->optionBuilder->populateWithArray($option)->create();
             }
         }
         $validationRules = array();
         if (is_array($data[AttributeMetadata::VALIDATION_RULES])) {
             foreach ($data[AttributeMetadata::VALIDATION_RULES] as $key => $value) {
                 $validationRules[$key] = $this->validationRuleBuilder->populateWithArray($value)->create();
             }
         }
         $data[AttributeMetadata::OPTIONS] = $options;
         $data[AttributeMetadata::VALIDATION_RULES] = $validationRules;
     }
     // fill frontend labels
     if (isset($data[AttributeMetadata::FRONTEND_LABEL]) && is_array($data[AttributeMetadata::FRONTEND_LABEL])) {
         $frontendLabel = [];
         foreach ($data[AttributeMetadata::FRONTEND_LABEL] as $key => $value) {
             $frontendLabel[$key] = $this->frontendLabelBuilder->populateWithArray($value)->create();
         }
         $data[AttributeMetadata::FRONTEND_LABEL] = $frontendLabel;
     }
     if (array_key_exists(AttributeMetadata::APPLY_TO, $data)) {
         $data[AttributeMetadata::APPLY_TO] = $this->processApplyToValue($data[AttributeMetadata::APPLY_TO]);
     }
     return parent::_setDataValues($data);
 }