Skip to content

Commit cdf6184

Browse files
committed
fix: store default metadata values only when set
1 parent db7e52f commit cdf6184

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

src/SearchIndexAdapter/Asset/MappingProviderInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
interface MappingProviderInterface
2222
{
23-
public const DEFAULT_METADATA = ['title', 'alt', 'copyright'];
24-
2523
/**
2624
* @return MappingProperty[]
2725
*/

src/SearchIndexAdapter/DefaultSearch/Asset/PredefinedAssetMetadataProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
final readonly class PredefinedAssetMetadataProvider implements MappingProviderInterface
2929
{
30+
private const DEFAULT_METADATA = ['title', 'alt', 'copyright'];
31+
3032
public function __construct(
3133
private LanguageServiceInterface $languageService,
3234
private FieldDefinitionServiceInterface $fieldDefinitionService
@@ -49,7 +51,7 @@ public function getMappingProperties(): array
4951
);
5052
}
5153

52-
return array_merge($mappingProperties, $this->getDefaultMetadataMapping());
54+
return array_merge($mappingProperties, $this->getDefaultMetadataMapping($languages));
5355
}
5456

5557
private function getTypeMapping(string $type): ?array
@@ -77,15 +79,15 @@ private function getLanguageMappingByType(array $languages, string $type): array
7779
/**
7880
* @return MappingProperty[]
7981
*/
80-
private function getDefaultMetadataMapping(): array
82+
private function getDefaultMetadataMapping(array $languages): array
8183
{
8284
$mappingProperties = [];
8385
foreach (self::DEFAULT_METADATA as $metadata) {
8486
$mappingProperties[] = new MappingProperty(
8587
$metadata,
8688
'input',
87-
$this->getLanguageMappingByType([MappingProperty::NOT_LOCALIZED_KEY], 'input'),
88-
[MappingProperty::NOT_LOCALIZED_KEY]
89+
$this->getLanguageMappingByType($languages, 'input'),
90+
$languages
8991
);
9092
}
9193

src/Service/SearchIndex/Asset/MetadataProviderService.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getSearchableMetaDataForAsset(Asset $asset): array
6262
}
6363
}
6464

65-
return $this->addDefaultMetadata($result);
65+
return $result;
6666
}
6767

6868
/**
@@ -90,32 +90,4 @@ private function getMappingProviders(): array
9090

9191
return $mappingProviders;
9292
}
93-
94-
private function addDefaultMetadata(array $assetMetadata): array
95-
{
96-
$indexedMetadata = array_flip(array_column($assetMetadata, 'name'));
97-
foreach ($this->getDefaultMetadataValues() as $defaultEntry) {
98-
if (!isset($indexedMetadata[$defaultEntry['name']])) {
99-
$assetMetadata[] = $defaultEntry;
100-
}
101-
}
102-
103-
return $assetMetadata;
104-
}
105-
106-
private function getDefaultMetadataValues(): array
107-
{
108-
$defaultMetadata = [];
109-
foreach (MappingProviderInterface::DEFAULT_METADATA as $key) {
110-
111-
$defaultMetadata[] = [
112-
'name' => $key,
113-
'type' => 'input',
114-
'language' => MappingProperty::NOT_LOCALIZED_KEY,
115-
'data' => '',
116-
];
117-
}
118-
119-
return $defaultMetadata;
120-
}
12193
}

0 commit comments

Comments
 (0)