Skip to content

Commit 1205cca

Browse files
author
Alexander Paliarush
committed
MAGETWO-31937: Exclude Extended Attributes from Custom Attributes List
1 parent ce8b94a commit 1205cca

File tree

16 files changed

+50
-201
lines changed

16 files changed

+50
-201
lines changed

app/code/Magento/Catalog/Model/Category/AttributeRepository.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ class AttributeRepository implements CategoryAttributeRepositoryInterface
2525
protected $eavAttributeRepository;
2626

2727
/**
28-
* @param \Magento\Framework\Api\Config\MetadataConfig $metadataConfig
2928
* @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder
3029
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
3130
* @param \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
3231
*/
3332
public function __construct(
34-
\Magento\Framework\Api\Config\MetadataConfig $metadataConfig,
3533
\Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder,
3634
\Magento\Framework\Api\FilterBuilder $filterBuilder,
3735
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
3836
) {
39-
$this->metadataConfig = $metadataConfig;
4037
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
4138
$this->filterBuilder = $filterBuilder;
4239
$this->eavAttributeRepository = $eavAttributeRepository;
@@ -66,6 +63,7 @@ public function get($attributeCode)
6663

6764
/**
6865
* {@inheritdoc}
66+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6967
*/
7068
public function getCustomAttributesMetadata($dataObjectClassName = null)
7169
{
@@ -78,12 +76,6 @@ public function getCustomAttributesMetadata($dataObjectClassName = null)
7876
]
7977
);
8078

81-
$customAttributes = [];
82-
$entityAttributes = $this->getList($searchCriteria->create())->getItems();
83-
84-
foreach ($entityAttributes as $attributeMetadata) {
85-
$customAttributes[] = $attributeMetadata;
86-
}
87-
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
79+
return $this->getList($searchCriteria->create())->getItems();
8880
}
8981
}

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
4949
*/
5050
protected $filterManager;
5151

52-
/**
53-
* @var \Magento\Framework\Api\Config\MetadataConfig
54-
*/
55-
protected $metadataConfig;
56-
5752
/**
5853
* @var \Magento\Framework\Api\SearchCriteriaDataBuilder
5954
*/
@@ -72,7 +67,6 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
7267
* @param \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
7368
* @param \Magento\Eav\Model\Config $eavConfig
7469
* @param \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory
75-
* @param \Magento\Framework\Api\Config\MetadataConfig $metadataConfig
7670
* @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder
7771
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
7872
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -85,7 +79,6 @@ public function __construct(
8579
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository,
8680
\Magento\Eav\Model\Config $eavConfig,
8781
\Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory,
88-
\Magento\Framework\Api\Config\MetadataConfig $metadataConfig,
8982
\Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder,
9083
\Magento\Framework\Api\FilterBuilder $filterBuilder
9184
) {
@@ -96,7 +89,6 @@ public function __construct(
9689
$this->eavAttributeRepository = $eavAttributeRepository;
9790
$this->eavConfig = $eavConfig;
9891
$this->inputtypeValidatorFactory = $validatorFactory;
99-
$this->metadataConfig = $metadataConfig;
10092
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
10193
$this->filterBuilder = $filterBuilder;
10294
}
@@ -224,6 +216,7 @@ public function deleteById($attributeCode)
224216

225217
/**
226218
* {@inheritdoc}
219+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
227220
*/
228221
public function getCustomAttributesMetadata($dataObjectClassName = null)
229222
{
@@ -236,13 +229,7 @@ public function getCustomAttributesMetadata($dataObjectClassName = null)
236229
]
237230
);
238231

239-
$customAttributes = [];
240-
$entityAttributes = $this->getList($searchCriteria->create())->getItems();
241-
242-
foreach ($entityAttributes as $attributeMetadata) {
243-
$customAttributes[] = $attributeMetadata;
244-
}
245-
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
232+
return $this->getList($searchCriteria->create())->getItems();
246233
}
247234

248235
/**

app/code/Magento/Customer/Model/Metadata/AddressMetadata.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Customer\Model\AttributeMetadataConverter;
1111
use Magento\Customer\Model\AttributeMetadataDataProvider;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13-
use Magento\Framework\Api\Config\MetadataConfig;
1413
use Magento\Framework\Api\SimpleDataObjectConverter;
1514
use Magento\Framework\Exception\NoSuchEntityException;
1615

@@ -24,11 +23,6 @@ class AddressMetadata implements AddressMetadataInterface
2423
*/
2524
private $addressDataObjectMethods;
2625

27-
/**
28-
* @var MetadataConfig
29-
*/
30-
private $metadataConfig;
31-
3226
/**
3327
* @var AttributeMetadataConverter
3428
*/
@@ -40,16 +34,13 @@ class AddressMetadata implements AddressMetadataInterface
4034
private $attributeMetadataDataProvider;
4135

4236
/**
43-
* @param MetadataConfig $metadataConfig
4437
* @param AttributeMetadataConverter $attributeMetadataConverter
4538
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
4639
*/
4740
public function __construct(
48-
MetadataConfig $metadataConfig,
4941
AttributeMetadataConverter $attributeMetadataConverter,
5042
AttributeMetadataDataProvider $attributeMetadataDataProvider
5143
) {
52-
$this->metadataConfig = $metadataConfig;
5344
$this->attributeMetadataConverter = $attributeMetadataConverter;
5445
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
5546
}
@@ -127,14 +118,14 @@ public function getAllAttributesMetadata()
127118
*/
128119
public function getCustomAttributesMetadata($dataObjectClassName = AddressMetadataInterface::DATA_INTERFACE_NAME)
129120
{
130-
$customAttributes = [];
131121
if (!$this->addressDataObjectMethods) {
132122
$dataObjectMethods = array_flip(get_class_methods($dataObjectClassName));
133123
$baseClassDataObjectMethods = array_flip(
134124
get_class_methods('Magento\Framework\Api\AbstractExtensibleObject')
135125
);
136126
$this->addressDataObjectMethods = array_diff_key($dataObjectMethods, $baseClassDataObjectMethods);
137127
}
128+
$customAttributes = [];
138129
foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
139130
$attributeCode = $attributeMetadata->getAttributeCode();
140131
$camelCaseKey = SimpleDataObjectConverter::snakeCaseToUpperCamelCase($attributeCode);
@@ -145,6 +136,6 @@ public function getCustomAttributesMetadata($dataObjectClassName = AddressMetada
145136
$customAttributes[] = $attributeMetadata;
146137
}
147138
}
148-
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
139+
return $customAttributes;
149140
}
150141
}

app/code/Magento/Customer/Model/Metadata/CustomerMetadata.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Customer\Model\AttributeMetadataConverter;
1111
use Magento\Customer\Model\AttributeMetadataDataProvider;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13-
use Magento\Framework\Api\Config\MetadataConfig;
1413
use Magento\Framework\Api\SimpleDataObjectConverter;
1514
use Magento\Framework\Exception\NoSuchEntityException;
1615

@@ -24,11 +23,6 @@ class CustomerMetadata implements CustomerMetadataInterface
2423
*/
2524
private $customerDataObjectMethods;
2625

27-
/**
28-
* @var MetadataConfig
29-
*/
30-
private $metadataConfig;
31-
3226
/**
3327
* @var AttributeMetadataConverter
3428
*/
@@ -40,16 +34,13 @@ class CustomerMetadata implements CustomerMetadataInterface
4034
private $attributeMetadataDataProvider;
4135

4236
/**
43-
* @param MetadataConfig $metadataConfig
4437
* @param AttributeMetadataConverter $attributeMetadataConverter
4538
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
4639
*/
4740
public function __construct(
48-
MetadataConfig $metadataConfig,
4941
AttributeMetadataConverter $attributeMetadataConverter,
5042
AttributeMetadataDataProvider $attributeMetadataDataProvider
5143
) {
52-
$this->metadataConfig = $metadataConfig;
5344
$this->attributeMetadataConverter = $attributeMetadataConverter;
5445
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
5546
}
@@ -148,6 +139,6 @@ public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_IN
148139
$customAttributes[] = $attributeMetadata;
149140
}
150141
}
151-
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
142+
return $customAttributes;
152143
}
153144
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,6 @@
8383
</argument>
8484
</arguments>
8585
</type>
86-
<virtualType name="Magento\Customer\Api\Config\CustomerMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
87-
<arguments>
88-
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\Customer\Model\AttributeMetadataDataBuilder</argument>
89-
</arguments>
90-
</virtualType>
91-
<type name="Magento\Customer\Model\Metadata\CustomerMetadata">
92-
<arguments>
93-
<argument name="metadataConfig" xsi:type="object">Magento\Customer\Api\Config\CustomerMetadataConfig</argument>
94-
</arguments>
95-
</type>
96-
<virtualType name="Magento\Customer\Api\Config\AddressMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
97-
<arguments>
98-
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\Customer\Model\AttributeMetadataDataBuilder</argument>
99-
</arguments>
100-
</virtualType>
101-
<type name="Magento\Customer\Model\Metadata\AddressMetadata">
102-
<arguments>
103-
<argument name="metadataConfig" xsi:type="object">Magento\Customer\Api\Config\AddressMetadataConfig</argument>
104-
</arguments>
105-
</type>
10686
<type name="Magento\Framework\Model\ActionValidator\RemoveAction">
10787
<arguments>
10888
<argument name="protectedModels" xsi:type="array">

app/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<preference for="Magento\Framework\Mview\View\ChangelogInterface" type="Magento\Framework\Mview\View\Changelog" />
8282
<preference for="Magento\Framework\View\Design\FileResolution\Fallback\CacheDataInterface" type="Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Flat"/>
8383
<preference for="Magento\Framework\Api\AttributeMetadataBuilderInterface" type="Magento\Framework\Api\AttributeMetadataBuilder"/>
84-
<preference for="Magento\Framework\Api\MetadataServiceInterface" type="Magento\Framework\Api\Config\MetadataConfig"/>
84+
<preference for="Magento\Framework\Api\MetadataServiceInterface" type="Magento\Framework\Api\DefaultMetadataService"/>
8585
<preference for="Magento\Framework\Api\SearchCriteriaInterface" type="Magento\Framework\Api\SearchCriteria"/>
8686
<preference for="Magento\Framework\App\Rss\UrlBuilderInterface" type="Magento\Framework\App\Rss\UrlBuilder"/>
8787
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Null"/>

dev/tests/api-functional/_files/Magento/TestModule1/etc/di.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,4 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
99
<preference for="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" type="Magento\TestModule1\Service\V1\AllSoapAndRest" />
1010
<preference for="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" type="Magento\TestModule1\Service\V2\AllSoapAndRest" />
11-
12-
<virtualType name="Magento\TestModule1\Service\Config\TestModule1MetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
13-
<arguments>
14-
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\TestModule1\Service\V1\Entity\Eav\AttributeMetadataBuilder</argument>
15-
<argument name="dataObjectClassName" xsi:type="string">Magento\TestModule1\Service\V1\Entity\Item</argument>
16-
</arguments>
17-
</virtualType>
18-
<type name="Magento\TestModule1\Service\V1\Entity\ItemBuilder">
19-
<arguments>
20-
<argument name="metadataService" xsi:type="object">Magento\TestModule1\Service\Config\TestModule1MetadataConfig</argument>
21-
</arguments>
22-
</type>
2311
</config>

dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@
1313
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject" />
1414
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeNestedDataObject" />
1515

16-
<virtualType name="Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
17-
<arguments>
18-
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\TestModuleMSC\Model\Data\Eav\AttributeMetadataBuilder</argument>
19-
<argument name="dataObjectClassName" xsi:type="string">Magento\TestModuleMSC\Model\Data\Item</argument>
20-
</arguments>
21-
</virtualType>
2216
<type name="Magento\TestModuleMSC\Model\Data\Item">
2317
<arguments>
2418
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\Resource\Item</argument>
25-
<argument name="metadataService" xsi:type="object">Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig</argument>
2619
</arguments>
2720
</type>
2821
<type name="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject">

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,7 @@
21052105
['Magento\Usa\Model\Shipping\Carrier\Usps\Source\Machinable', 'Magento\Usps\Model\Source\Machinable'],
21062106
['Magento\Usa\Model\Shipping\Carrier\Usps\Source\Method', 'Magento\Usps\Model\Source\Method'],
21072107
['Magento\Usa\Model\Shipping\Carrier\Usps\Source\Size', 'Magento\Usps\Model\Source\Size'],
2108+
['Magento\Framework\Api\Config\MetadataConfig'],
21082109
['Magento\Usa\Model\Shipping\Carrier\Usps', 'Magento\Usps\Model\Carrier'],
21092110
['Magento\Usa\Model\Shipping\Carrier\Ups', 'Magento\Ups\Model\Carrier'],
21102111
['Magento\Usa\Model\Simplexml\Element', 'Magento\Shipping\Model\Simplexml\Element'],

dev/tests/unit/testsuite/Magento/Catalog/Model/Category/AttributeRepositoryTest.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ class AttributeRepositoryTest extends \PHPUnit_Framework_TestCase
3131
*/
3232
protected $attributeRepositoryMock;
3333

34-
/**
35-
* @var \PHPUnit_Framework_MockObject_MockObject
36-
*/
37-
protected $metadataConfigMock;
38-
3934
/**
4035
* @var \PHPUnit_Framework_MockObject_MockObject
4136
*/
@@ -49,8 +44,6 @@ protected function setUp()
4944
$this->getMock('Magento\Framework\Api\FilterBuilder', [], [], '', false);
5045
$this->attributeRepositoryMock =
5146
$this->getMock('Magento\Eav\Api\AttributeRepositoryInterface', [], [], '', false);
52-
$this->metadataConfigMock =
53-
$this->getMock('Magento\Framework\Api\Config\MetadataConfig', [], [], '', false);
5447
$this->searchResultMock =
5548
$this->getMock(
5649
'Magento\Framework\Api\SearchResultsInterface',
@@ -62,12 +55,16 @@ protected function setUp()
6255
],
6356
[],
6457
'',
65-
false);
66-
$this->model = new AttributeRepository(
67-
$this->metadataConfigMock,
68-
$this->searchBuilderMock,
69-
$this->filterBuilderMock,
70-
$this->attributeRepositoryMock
58+
false
59+
);
60+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
61+
$this->model = $objectManager->getObject(
62+
'Magento\Catalog\Model\Category\AttributeRepository',
63+
[
64+
'searchCriteriaBuilder' => $this->searchBuilderMock,
65+
'filterBuilder' => $this->filterBuilderMock,
66+
'eavAttributeRepository' => $this->attributeRepositoryMock
67+
]
7168
);
7269
}
7370

@@ -113,9 +110,7 @@ public function testGetCustomAttributesMetadata()
113110
$searchCriteriaMock
114111
)->willReturn($this->searchResultMock);
115112
$this->searchResultMock->expects($this->once())->method('getItems')->willReturn([$itemMock]);
116-
$this->metadataConfigMock->expects($this->once())
117-
->method('getCustomAttributesMetadata')->with(null)->willReturn(['attribute']);
118-
$expected = array_merge([$itemMock], ['attribute']);
113+
$expected = [$itemMock];
119114

120115
$this->assertEquals($expected, $this->model->getCustomAttributesMetadata(null));
121116
}

0 commit comments

Comments
 (0)