Skip to content

Commit 42e12e9

Browse files
authored
set null metadata as empty (#1781)
1 parent c434ca8 commit 42e12e9

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/Metadata/Patcher/Adapter/CustomMetadataAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function patch(ElementInterface $element, array $data, UserInterface $use
9595
];
9696

9797
if (!empty($patchedMetadata)) {
98-
$element->setMetadata($patchedMetadata);
98+
$element->setMetadata($this->dataResolverService->prepareData($patchedMetadata));
9999
}
100100
}
101101

src/Metadata/Service/DataResolverServiceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
interface DataResolverServiceInterface
2323
{
24+
public function prepareData(array $customMetadata): array;
25+
2426
/**
2527
* @throws InvalidArgumentException
2628
*/

src/Metadata/Service/DataResolverServiceService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public function __construct(private DataAdapterServiceInterface $dataAdapterServ
2525
{
2626
}
2727

28+
public function prepareData(array $customMetadata): array
29+
{
30+
foreach ($customMetadata as $key => $metadata) {
31+
$customMetadata[$key]['data'] = $metadata['data'] ?? '';
32+
}
33+
34+
return $customMetadata;
35+
}
36+
2837
/**
2938
* {@inheritdoc}
3039
*/

src/Metadata/Updater/Adapter/CustomMetadataAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function update(ElementInterface $element, array $data): void
5252

5353
$this->eventDispatcher->dispatch($metadataEvent, CustomMetadataEvent::EVENT_NAME);
5454

55-
$element->setMetadata($metadataEvent->getCustomMetadata());
55+
$element->setMetadata($this->dataResolverService->prepareData($metadataEvent->getCustomMetadata()));
5656
}
5757

5858
public function getIndexKey(): string

0 commit comments

Comments
 (0)