From d9e178d52670fe11fa35532efa4e04b4e77b92cb Mon Sep 17 00:00:00 2001 From: ciastektk Date: Tue, 9 Jan 2024 07:42:19 +0100 Subject: [PATCH] IBX-7367: Added config provider for image picker (#1052) --- .../Resources/config/default_parameters.yaml | 8 +++ .../config/services/ui_config/common.yaml | 9 ++++ .../UI/Config/Provider/Module/ImagePicker.php | 40 +++++++++++++++ .../Provider/Module/ImagePickerTest.php | 51 +++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 src/lib/UI/Config/Provider/Module/ImagePicker.php create mode 100644 tests/lib/UI/Config/Provider/Module/ImagePickerTest.php diff --git a/src/bundle/Resources/config/default_parameters.yaml b/src/bundle/Resources/config/default_parameters.yaml index be565731e7..3b662cc0a1 100644 --- a/src/bundle/Resources/config/default_parameters.yaml +++ b/src/bundle/Resources/config/default_parameters.yaml @@ -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 diff --git a/src/bundle/Resources/config/services/ui_config/common.yaml b/src/bundle/Resources/config/services/ui_config/common.yaml index 026ef750dc..402dd5de5d 100644 --- a/src/bundle/Resources/config/services/ui_config/common.yaml +++ b/src/bundle/Resources/config/services/ui_config/common.yaml @@ -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: diff --git a/src/lib/UI/Config/Provider/Module/ImagePicker.php b/src/lib/UI/Config/Provider/Module/ImagePicker.php new file mode 100644 index 0000000000..70a5911d1c --- /dev/null +++ b/src/lib/UI/Config/Provider/Module/ImagePicker.php @@ -0,0 +1,40 @@ +, + * imageContentTypeIdentifiers: array, + * aggregations: array>, + * } + */ +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; + } +} diff --git a/tests/lib/UI/Config/Provider/Module/ImagePickerTest.php b/tests/lib/UI/Config/Provider/Module/ImagePickerTest.php new file mode 100644 index 0000000000..c753db4635 --- /dev/null +++ b/tests/lib/UI/Config/Provider/Module/ImagePickerTest.php @@ -0,0 +1,51 @@ + [ + '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() + ); + } +}