Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/lib/UI/Config/Provider/Module/DamWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*/
final class DamWidget implements ProviderInterface
{
private const IMAGE_TYPE_ID = 5;

/** @phpstan-var TConfig */
private array $config;

Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not hardcode database IDs. There's no guarantee on a real instance, that a given ID will reference what you need it to reference.

  1. Add to ibexa.dam_widget.image.mappings.image DI parameter contentTypeIdentifier: image key-value and use it as $this->config['image']['contentTypeIdentifier'].

  2. Load the content type using loadContentTypeByIdentifier instead.

  3. Make sure to handle NotFoundException as there's no guarantee an instance has image content type defined (or defined using that identifier). In such case an error should be logged.

foreach ($this->config['image']['aggregations'] as $key => $aggregation) {
if ($imageType->hasFieldDefinition($aggregation['fieldDefinitionIdentifier'])) {
$imageConfig['aggregations'][$key] = $aggregation;
}
}

$mappings = [];
$contentTypeIdentifiers = [];
$fieldDefinitionIdentifiers = [];
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/UI/Config/Provider/Module/DamWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function testGetConfig(
$this->mockRepositoryConfigurationProviderGetRepositoryConfig($repositoryConfig);
$this->mockContentTypeServiceLoadContentTypeByIdentifier($loadContentTypeValueMap);
$this->mockSchemaIdentifierExtractorExtract($extractSchemaIdentifiersValueMap);
$this->mockContentTypeServiceLoadContentType();

self::assertEquals(
$expectedConfiguration,
Expand Down Expand Up @@ -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<array{string|array<string>}> $valueMap
*/
Expand Down
Loading