Skip to content

Commit 8412a43

Browse files
authored
ENGCOM-5690: Standardize the array structure for the getAttributes result #23818
2 parents 9cb846b + 74546ea commit 8412a43

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

app/code/Magento/Eav/Model/AttributeProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Eav\Model;
89

@@ -52,7 +53,7 @@ public function __construct(
5253
* Returns array of fields
5354
*
5455
* @param string $entityType
55-
* @return array
56+
* @return string[]
5657
* @throws \Exception
5758
*/
5859
public function getAttributes($entityType)
@@ -66,6 +67,7 @@ public function getAttributes($entityType)
6667
foreach ($searchResult->getItems() as $attribute) {
6768
$attributes[] = $attribute->getAttributeCode();
6869
}
70+
6971
return $attributes;
7072
}
7173
}

lib/internal/Magento/Framework/Model/EntitySnapshot.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Model;
89

@@ -44,6 +45,8 @@ public function __construct(
4445
}
4546

4647
/**
48+
* Register snapshot of entity data.
49+
*
4750
* @param string $entityType
4851
* @param object $entity
4952
* @return void
@@ -55,7 +58,7 @@ public function registerSnapshot($entityType, $entity)
5558
$entityData = $hydrator->extract($entity);
5659
$attributes = $this->attributeProvider->getAttributes($entityType);
5760
$this->snapshotData[$entityType][$entityData[$metadata->getIdentifierField()]]
58-
= array_intersect_key($entityData, $attributes);
61+
= array_intersect(\array_keys($entityData), $attributes);
5962
}
6063

6164
/**

lib/internal/Magento/Framework/Model/EntitySnapshot/AttributeProvider.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Model\EntitySnapshot;
89

@@ -53,31 +54,29 @@ public function __construct(
5354
* Returns array of fields
5455
*
5556
* @param string $entityType
56-
* @return array
57+
* @return string[]
5758
* @throws \Exception
5859
*/
5960
public function getAttributes($entityType)
6061
{
6162
if (!isset($this->registry[$entityType])) {
6263
$metadata = $this->metadataPool->getMetadata($entityType);
63-
$this->registry[$entityType] = $metadata->getEntityConnection()->describeTable($metadata->getEntityTable());
64-
if ($metadata->getLinkField() != $metadata->getIdentifierField()) {
65-
unset($this->registry[$entityType][$metadata->getLinkField()]);
66-
}
67-
$providers = [];
68-
if (isset($this->providers[$entityType])) {
69-
$providers = $this->providers[$entityType];
70-
} elseif (isset($this->providers['default'])) {
71-
$providers = $this->providers['default'];
64+
$entityDescription = $metadata->getEntityConnection()->describeTable($metadata->getEntityTable());
65+
if ($metadata->getLinkField() !== $metadata->getIdentifierField()) {
66+
unset($entityDescription[$metadata->getLinkField()]);
7267
}
68+
$attributes = [];
69+
$attributes[] = \array_keys($entityDescription);
70+
71+
$providers = $this->providers[$entityType] ?? $this->providers['default'] ?? [];
7372
foreach ($providers as $providerClass) {
7473
$provider = $this->objectManager->get($providerClass);
75-
$this->registry[$entityType] = array_merge(
76-
$this->registry[$entityType],
77-
$provider->getAttributes($entityType)
78-
);
74+
$attributes[] = $provider->getAttributes($entityType);
7975
}
76+
77+
$this->registry[$entityType] = \array_merge(...$attributes);
8078
}
79+
8180
return $this->registry[$entityType];
8281
}
8382
}

lib/internal/Magento/Framework/Model/EntitySnapshot/AttributeProviderInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Model\EntitySnapshot;
89

@@ -12,8 +13,10 @@
1213
interface AttributeProviderInterface
1314
{
1415
/**
16+
* Returns array of fields
17+
*
1518
* @param string $entityType
16-
* @return array
19+
* @return string[]
1720
*/
1821
public function getAttributes($entityType);
1922
}

0 commit comments

Comments
 (0)