Skip to content

Commit

Permalink
IBX-7367: Added config provider for image picker (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk authored Jan 9, 2024
1 parent 67e85ee commit d9e178d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bundle/Resources/config/default_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ parameters:
ibexa.admin_ui.content_tree.node_factory.max_location_ids_in_single_aggregation: 100

ibexa.site_access.config.default.admin_ui.default_focus_mode: '1'

ibexa.image_picker.field_definition_identifiers: [image]
ibexa.image_picker.content_type_identifiers: [image]
ibexa.image_picker.aggregations:
KeywordTermAggregation:
name: keywords
contentTypeIdentifier: image
fieldDefinitionIdentifier: tags
9 changes: 9 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ services:
tags:
- { name: ibexa.admin_ui.config.provider, key: 'userProfile' }

Ibexa\AdminUi\UI\Config\Provider\Module\ImagePicker:
arguments:
$config:
imageFieldDefinitionIdentifiers: '%ibexa.image_picker.field_definition_identifiers%'
imageContentTypeIdentifiers: '%ibexa.image_picker.content_type_identifiers%'
aggregations: '%ibexa.image_picker.aggregations%'
tags:
- { name: ibexa.admin_ui.config.provider, key: 'imagePicker' }

# Resolvers
Ibexa\AdminUi\REST\Generator\ApplicationConfigRestGeneratorRegistry:
arguments:
Expand Down
40 changes: 40 additions & 0 deletions src/lib/UI/Config/Provider/Module/ImagePicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\UI\Config\Provider\Module;

use Ibexa\Contracts\AdminUi\UI\Config\ProviderInterface;

/**
* @template TConfig of array{
* imageFieldDefinitionIdentifiers: array<string>,
* imageContentTypeIdentifiers: array<string>,
* aggregations: array<string, array<string, string>>,
* }
*/
final class ImagePicker implements ProviderInterface
{
/** @phpstan-var TConfig */
private array $config;

/**
* @phpstan-param TConfig $config
*/
public function __construct(array $config)
{
$this->config = $config;
}

/**
* @phpstan-return TConfig
*/
public function getConfig(): array
{
return $this->config;
}
}
51 changes: 51 additions & 0 deletions tests/lib/UI/Config/Provider/Module/ImagePickerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\AdminUi\UI\Config\Provider\Module;

use Ibexa\AdminUi\UI\Config\Provider\Module\ImagePicker;
use Ibexa\Contracts\AdminUi\UI\Config\ProviderInterface;
use PHPUnit\Framework\TestCase;

final class ImagePickerTest extends TestCase
{
private const FIELD_DEFINITION_IDENTIFIERS = ['field_foo', 'field_bar'];
private const CONTENT_TYPE_IDENTIFIERS = ['content_type_foo', 'content_type_bar'];
private const AGGREGATIONS = [
'KeywordTermAggregation' => [
'name' => 'keywords',
'contentTypeIdentifier' => 'keywords',
'fieldDefinitionIdentifier' => 'keywords',
],
];

private ProviderInterface $provider;

protected function setUp(): void
{
$this->provider = new ImagePicker(
[
'imageFieldDefinitionIdentifiers' => self::FIELD_DEFINITION_IDENTIFIERS,
'imageContentTypeIdentifiers' => self::CONTENT_TYPE_IDENTIFIERS,
'aggregations' => self::AGGREGATIONS,
]
);
}

public function testGetConfig(): void
{
self::assertSame(
[
'imageFieldDefinitionIdentifiers' => self::FIELD_DEFINITION_IDENTIFIERS,
'imageContentTypeIdentifiers' => self::CONTENT_TYPE_IDENTIFIERS,
'aggregations' => self::AGGREGATIONS,
],
$this->provider->getConfig()
);
}
}

0 comments on commit d9e178d

Please sign in to comment.