Skip to content

Commit 387386c

Browse files
author
Yu Tang
committed
MAGETWO-33101: Refactor code that uses customer builders in Customer module
- Refactored usage of Magento\Customer\Model\AttributeMetadataDataBuilder
1 parent 5409dfa commit 387386c

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Addresses.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Customer\Controller\RegistryConstants;
99
use Magento\Customer\Api\AddressMetadataInterface;
10-
use Magento\Customer\Model\AttributeMetadataDataBuilder;
1110
use Magento\Customer\Api\Data\AddressInterface;
1211
use Magento\Customer\Api\AccountManagementInterface;
1312
use Magento\Customer\Api\Data\AddressInterfaceFactory;
@@ -67,9 +66,6 @@ class Addresses extends GenericMetadata
6766
/** @var CustomerInterfaceFactory */
6867
protected $customerDataFactory;
6968

70-
/** @var AttributeMetadataDataBuilder */
71-
protected $_attributeMetadataBuilder;
72-
7369
/**
7470
* @var AddressMapper
7571
*/
@@ -96,7 +92,6 @@ class Addresses extends GenericMetadata
9692
* @param AddressMetadataInterface $addressMetadataService
9793
* @param AddressInterfaceFactory $addressDataFactory
9894
* @param CustomerInterfaceFactory $customerInterfaceFactory
99-
* @param AttributeMetadataDataBuilder $attributeMetadataBuilder
10095
* @param \Magento\Directory\Helper\Data $directoryHelper
10196
* @param AddressMapper $addressMapper
10297
* @param CustomerMapper $customerMapper
@@ -121,7 +116,6 @@ public function __construct(
121116
AddressMetadataInterface $addressMetadataService,
122117
AddressInterfaceFactory $addressDataFactory,
123118
CustomerInterfaceFactory $customerInterfaceFactory,
124-
AttributeMetadataDataBuilder $attributeMetadataBuilder,
125119
\Magento\Directory\Helper\Data $directoryHelper,
126120
AddressMapper $addressMapper,
127121
DataObjectHelper $dataObjectHelper,
@@ -138,7 +132,6 @@ public function __construct(
138132
$this->_addressMetadataService = $addressMetadataService;
139133
$this->addressDataFactory = $addressDataFactory;
140134
$this->customerDataFactory = $customerInterfaceFactory;
141-
$this->_attributeMetadataBuilder = $attributeMetadataBuilder;
142135
$this->_directoryHelper = $directoryHelper;
143136
$this->addressMapper = $addressMapper;
144137
$this->dataObjectHelper = $dataObjectHelper;
@@ -261,21 +254,12 @@ public function initForm()
261254
$attributes = $addressForm->getAttributes();
262255
if (isset($attributes['street'])) {
263256
if ($attributes['street']->getMultilineCount() <= 0) {
264-
$attributes['street'] = $this->_attributeMetadataBuilder->populate(
265-
$attributes['street']
266-
)->setMultilineCount(
267-
self::DEFAULT_STREET_LINES_COUNT
268-
)->create();
257+
$attributes['street']->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT);
269258
}
270259
}
271260
foreach ($attributes as $key => $attribute) {
272-
$attributes[$key] = $this->_attributeMetadataBuilder->populate(
273-
$attribute
274-
)->setFrontendLabel(
275-
__($attribute->getFrontendLabel())
276-
)->setVisible(
277-
false
278-
)->create();
261+
$attributes[$key]->setFrontendLabel(__($attribute->getFrontendLabel()))
262+
->setIsVisible(false);
279263
}
280264
$this->_setFieldset($attributes, $fieldset);
281265

app/code/Magento/Customer/Model/AttributeMetadataConverter.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Customer\Api\Data\OptionInterfaceFactory;
99
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
10+
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
1011

1112
/**
1213
* Converter for AttributeMetadata
@@ -24,9 +25,9 @@ class AttributeMetadataConverter
2425
private $validationRuleFactory;
2526

2627
/**
27-
* @var AttributeMetadataDataBuilder
28+
* @var AttributeMetadataInterfaceFactory
2829
*/
29-
private $_attributeMetadataBuilder;
30+
private $attributeMetadataFactory;
3031

3132
/**
3233
* @var \Magento\Framework\Api\DataObjectHelper
@@ -37,18 +38,18 @@ class AttributeMetadataConverter
3738
*
3839
* @param OptionInterfaceFactory $optionFactory
3940
* @param ValidationRuleInterfaceFactory $validationRuleFactory
40-
* @param AttributeMetadataDataBuilder $attributeMetadataBuilder
41+
* @param AttributeMetadataInterfaceFactory $attributeMetadataFactory
4142
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
4243
*/
4344
public function __construct(
4445
OptionInterfaceFactory $optionFactory,
4546
ValidationRuleInterfaceFactory $validationRuleFactory,
46-
AttributeMetadataDataBuilder $attributeMetadataBuilder,
47+
AttributeMetadataInterfaceFactory $attributeMetadataFactory,
4748
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
4849
) {
4950
$this->optionFactory = $optionFactory;
5051
$this->validationRuleFactory = $validationRuleFactory;
51-
$this->_attributeMetadataBuilder = $attributeMetadataBuilder;
52+
$this->attributeMetadataFactory = $attributeMetadataFactory;
5253
$this->dataObjectHelper = $dataObjectHelper;
5354
}
5455

@@ -87,24 +88,23 @@ public function createMetadataAttribute($attribute)
8788
$validationRules[] = $validationRule;
8889
}
8990

90-
$this->_attributeMetadataBuilder->setAttributeCode($attribute->getAttributeCode())
91+
92+
return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())
9193
->setFrontendInput($attribute->getFrontendInput())
9294
->setInputFilter((string)$attribute->getInputFilter())
9395
->setStoreLabel($attribute->getStoreLabel())
9496
->setValidationRules($validationRules)
95-
->setVisible((boolean)$attribute->getIsVisible())
96-
->setRequired((boolean)$attribute->getIsRequired())
97+
->setIsVisible((boolean)$attribute->getIsVisible())
98+
->setIsRequired((boolean)$attribute->getIsRequired())
9799
->setMultilineCount((int)$attribute->getMultilineCount())
98100
->setDataModel((string)$attribute->getDataModel())
99101
->setOptions($options)
100102
->setFrontendClass($attribute->getFrontend()->getClass())
101103
->setFrontendLabel($attribute->getFrontendLabel())
102104
->setNote((string)$attribute->getNote())
103-
->setSystem((boolean)$attribute->getIsSystem())
104-
->setUserDefined((boolean)$attribute->getIsUserDefined())
105+
->setIsSystem((boolean)$attribute->getIsSystem())
106+
->setIsUserDefined((boolean)$attribute->getIsUserDefined())
105107
->setBackendType($attribute->getBackendType())
106108
->setSortOrder((int)$attribute->getSortOrder());
107-
108-
return $this->_attributeMetadataBuilder->create();
109109
}
110110
}

0 commit comments

Comments
 (0)