diff --git a/src/lib/UI/Config/Provider/Module/DamWidget.php b/src/lib/UI/Config/Provider/Module/DamWidget.php index 40363e5712..b4375bfc46 100644 --- a/src/lib/UI/Config/Provider/Module/DamWidget.php +++ b/src/lib/UI/Config/Provider/Module/DamWidget.php @@ -51,6 +51,8 @@ */ final class DamWidget implements ProviderInterface { + private const IMAGE_TYPE_ID = 5; + /** @phpstan-var TConfig */ private array $config; @@ -100,10 +102,18 @@ private function getImageConfig(): array { $imageConfig = [ 'showImageFilters' => $this->showImageFilters(), - 'aggregations' => $this->config['image']['aggregations'], + 'aggregations' => [], 'enableMultipleDownload' => extension_loaded('zip'), ]; + // The content type may not have the default fields; in that case, don't add the aggregations + $imageType = $this->contentTypeService->loadContentType(self::IMAGE_TYPE_ID); + foreach ($this->config['image']['aggregations'] as $key => $aggregation) { + if ($imageType->hasFieldDefinition($aggregation['fieldDefinitionIdentifier'])) { + $imageConfig['aggregations'][$key] = $aggregation; + } + } + $mappings = []; $contentTypeIdentifiers = []; $fieldDefinitionIdentifiers = []; diff --git a/tests/lib/UI/Config/Provider/Module/DamWidgetTest.php b/tests/lib/UI/Config/Provider/Module/DamWidgetTest.php index 758261ebe9..69012fb338 100644 --- a/tests/lib/UI/Config/Provider/Module/DamWidgetTest.php +++ b/tests/lib/UI/Config/Provider/Module/DamWidgetTest.php @@ -137,6 +137,7 @@ public function testGetConfig( $this->mockRepositoryConfigurationProviderGetRepositoryConfig($repositoryConfig); $this->mockContentTypeServiceLoadContentTypeByIdentifier($loadContentTypeValueMap); $this->mockSchemaIdentifierExtractorExtract($extractSchemaIdentifiersValueMap); + $this->mockContentTypeServiceLoadContentType(); self::assertEquals( $expectedConfiguration, @@ -263,6 +264,16 @@ private function mockContentTypeServiceLoadContentTypeByIdentifier(array $valueM ->willReturnMap($valueMap); } + private function mockContentTypeServiceLoadContentType(): void + { + $contetnType = $this->createMock(ContentType::class); + $contetnType->method('hasFieldDefinition')->willReturn(true); + + $this->contentTypeService + ->method('loadContentType') + ->willReturn($contetnType); + } + /** * @param array}> $valueMap */