From d18419a230b66490b844c685be125cff4bcb8386 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 14:21:24 +0200 Subject: [PATCH 01/22] Initial grid api functionality --- config/grid.yaml | 24 +++++ .../Grid/Configuration/GetController.php | 74 ++++++++++++++++ .../CompilerPass/GridColumnAdapterPass.php | 49 +++++++++++ src/Grid/Adapter/ColumnAdapterInterface.php | 31 +++++++ src/Grid/Adapter/IntegerColumnAdapter.php | 44 ++++++++++ src/Grid/Mapper/ColumnMapper.php | 46 ++++++++++ src/Grid/Mapper/ColumnMapperInterface.php | 25 ++++++ src/Grid/Schema/ColumnDefinition.php | 87 +++++++++++++++++++ src/Grid/Schema/Configuration.php | 52 +++++++++++ src/Grid/Service/AdapterLoaderInterface.php | 31 +++++++ src/Grid/Service/GridService.php | 82 +++++++++++++++++ src/Grid/Service/GridServiceInterface.php | 34 ++++++++ .../Service/Loader/TaggedIteratorAdapter.php | 50 +++++++++++ src/Grid/Service/SystemColumnService.php | 42 +++++++++ .../Service/SystemColumnServiceInterface.php | 25 ++++++ 15 files changed, 696 insertions(+) create mode 100644 config/grid.yaml create mode 100644 src/Asset/Controller/Grid/Configuration/GetController.php create mode 100644 src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php create mode 100644 src/Grid/Adapter/ColumnAdapterInterface.php create mode 100644 src/Grid/Adapter/IntegerColumnAdapter.php create mode 100644 src/Grid/Mapper/ColumnMapper.php create mode 100644 src/Grid/Mapper/ColumnMapperInterface.php create mode 100644 src/Grid/Schema/ColumnDefinition.php create mode 100644 src/Grid/Schema/Configuration.php create mode 100644 src/Grid/Service/AdapterLoaderInterface.php create mode 100644 src/Grid/Service/GridService.php create mode 100644 src/Grid/Service/GridServiceInterface.php create mode 100644 src/Grid/Service/Loader/TaggedIteratorAdapter.php create mode 100644 src/Grid/Service/SystemColumnService.php create mode 100644 src/Grid/Service/SystemColumnServiceInterface.php diff --git a/config/grid.yaml b/config/grid.yaml new file mode 100644 index 000000000..1cf5a7e6f --- /dev/null +++ b/config/grid.yaml @@ -0,0 +1,24 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapperInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapper + + Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridService + + Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnService + + Pimcore\Bundle\StudioBackendBundle\Grid\Service\AdapterLoaderInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorAdapter + + # + # Adapter + # + + Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\IntegerColumnAdapter: + tags: [ 'pimcore.studio_backend.grid_column_adapter' ] diff --git a/src/Asset/Controller/Grid/Configuration/GetController.php b/src/Asset/Controller/Grid/Configuration/GetController.php new file mode 100644 index 000000000..8fc5e066d --- /dev/null +++ b/src/Asset/Controller/Grid/Configuration/GetController.php @@ -0,0 +1,74 @@ +value)] + #[Get( + path: self::API_PATH . '/assets/grid/configuration', + operationId: 'getAssetGridConfiguration', + description: 'Get assets grid configuration', + summary: 'Get default assets grid configuration', + tags: [Tags::Assets->name] + )] + #[SuccessResponse( + description: 'Grid configuration', + content: new JsonContent( + ref: Configuration::class + ) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + ])] + public function getAssetGridConfiguration(): JsonResponse + { + return $this->jsonResponse($this->gridService->getAssetGridConfiguration()); + } +} diff --git a/src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php b/src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php new file mode 100644 index 000000000..1b3d09b40 --- /dev/null +++ b/src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php @@ -0,0 +1,49 @@ +findTaggedServiceIds(TaggedIteratorAdapter::ADAPTER_TAG), + + ] + ); + + foreach ($taggedServices as $environmentType) { + $this->checkInterface($environmentType, ColumnAdapterInterface::class); + } + } +} diff --git a/src/Grid/Adapter/ColumnAdapterInterface.php b/src/Grid/Adapter/ColumnAdapterInterface.php new file mode 100644 index 000000000..c7a6de39c --- /dev/null +++ b/src/Grid/Adapter/ColumnAdapterInterface.php @@ -0,0 +1,31 @@ + 'image', + 'id' => 'integer', + 'type' => 'string', + 'fullpath' => 'string', + 'filename' => 'string', + 'creationDate' => 'datetime', + 'modificationDate' => 'datetime', + 'size' => 'integer' + ]; + + + public function getType(string $column): string + { + if(!array_key_exists($column, self::COLUMN_MAPPING)) { + throw new InvalidArgumentException('Column not found'); + } + + return self::COLUMN_MAPPING[$column]; + } +} \ No newline at end of file diff --git a/src/Grid/Mapper/ColumnMapperInterface.php b/src/Grid/Mapper/ColumnMapperInterface.php new file mode 100644 index 000000000..9adf38c8a --- /dev/null +++ b/src/Grid/Mapper/ColumnMapperInterface.php @@ -0,0 +1,25 @@ + 'value'])] + private array $config, + ) + { + + } + + public function getConfig(): array + { + return $this->config; + } + + public function getKey(): string + { + return $this->key; + } + + public function getGroup(): string + { + return $this->group; + } + + public function isSortable(): bool + { + return $this->sortable; + } + + public function isEditable(): bool + { + return $this->editable; + } + + public function isLocalizable(): bool + { + return $this->localizable; + } + + public function getType(): string + { + return $this->type; + } +} \ No newline at end of file diff --git a/src/Grid/Schema/Configuration.php b/src/Grid/Schema/Configuration.php new file mode 100644 index 000000000..4ee3d2661 --- /dev/null +++ b/src/Grid/Schema/Configuration.php @@ -0,0 +1,52 @@ + $columns + */ + public function __construct( + #[Property( + property: 'columns', + type: 'array', + items: new Items(ref: ColumnDefinition::class) + )] + private array $columns, + ) { + } + + /** + * @return array + */ + public function getColumns(): array + { + return $this->columns; + } +} \ No newline at end of file diff --git a/src/Grid/Service/AdapterLoaderInterface.php b/src/Grid/Service/AdapterLoaderInterface.php new file mode 100644 index 000000000..744725d89 --- /dev/null +++ b/src/Grid/Service/AdapterLoaderInterface.php @@ -0,0 +1,31 @@ + + */ + public function loadAdapters(): array; +} diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php new file mode 100644 index 000000000..f863748d1 --- /dev/null +++ b/src/Grid/Service/GridService.php @@ -0,0 +1,82 @@ + $adapters + */ + private array $adapters; + + public function __construct( + AdapterLoaderInterface $adapterLoader, + private SystemColumnServiceInterface $systemColumnService + ) { + $this->adapters = $adapterLoader->loadAdapters(); + } + public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array + { + // $data = []; + // foreach($configuration->getColumns() as $column) { + // $data[$column->getKey()] = $column->getData($element); + // } + + // return $data; + return []; + } + + public function getAssetGridConfiguration(): Configuration + { + $systemColumns = $this->systemColumnService->getSystemColumnsForAssets(); + $columns = []; + foreach($systemColumns as $columnKey => $type) { + if(!array_key_exists($type, $this->adapters)) { + continue; + } + $columns[] = new ColumnDefinition( + key: $columnKey, + group: 'system', + sortable: $this->adapters[$type]->isSortable(), + editable: false, + localizable: false, + type: $type, + config: $this->adapters[$type]->getConfig() + ); + } + return new Configuration($columns); + } + + public function getDocumentGridColumns(): Configuration + { + return new Configuration([]); + } + + public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration + { + return new Configuration([]); + } +} diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php new file mode 100644 index 000000000..331423110 --- /dev/null +++ b/src/Grid/Service/GridServiceInterface.php @@ -0,0 +1,34 @@ + $taggedAdapter + */ + public function __construct( + #[TaggedIterator(self::ADAPTER_TAG)] + private readonly iterable $taggedAdapter, + ) { + } + + /** + * @return array + */ + public function loadAdapters(): array + { + $adapters = []; + foreach($this->taggedAdapter as $adapter) { + $adapters[$adapter->getType()] = $adapter; + } + return $adapters; + } +} diff --git a/src/Grid/Service/SystemColumnService.php b/src/Grid/Service/SystemColumnService.php new file mode 100644 index 000000000..b9e6a18d6 --- /dev/null +++ b/src/Grid/Service/SystemColumnService.php @@ -0,0 +1,42 @@ +columnMapper->getType($column); + } + + return $columns; + } +} \ No newline at end of file diff --git a/src/Grid/Service/SystemColumnServiceInterface.php b/src/Grid/Service/SystemColumnServiceInterface.php new file mode 100644 index 000000000..557ed0aec --- /dev/null +++ b/src/Grid/Service/SystemColumnServiceInterface.php @@ -0,0 +1,25 @@ + Date: Mon, 1 Jul 2024 12:23:09 +0000 Subject: [PATCH 02/22] Apply php-cs-fixer changes --- src/Grid/Adapter/ColumnAdapterInterface.php | 2 +- src/Grid/Adapter/IntegerColumnAdapter.php | 3 +-- src/Grid/Mapper/ColumnMapper.php | 13 ++++++------- src/Grid/Mapper/ColumnMapperInterface.php | 2 +- src/Grid/Schema/ColumnDefinition.php | 6 +++--- src/Grid/Schema/Configuration.php | 2 +- src/Grid/Service/AdapterLoaderInterface.php | 1 - src/Grid/Service/GridService.php | 12 +++++++----- src/Grid/Service/GridServiceInterface.php | 3 ++- src/Grid/Service/Loader/TaggedIteratorAdapter.php | 3 ++- src/Grid/Service/SystemColumnService.php | 2 +- src/Grid/Service/SystemColumnServiceInterface.php | 2 +- 12 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Grid/Adapter/ColumnAdapterInterface.php b/src/Grid/Adapter/ColumnAdapterInterface.php index c7a6de39c..59c8bf091 100644 --- a/src/Grid/Adapter/ColumnAdapterInterface.php +++ b/src/Grid/Adapter/ColumnAdapterInterface.php @@ -28,4 +28,4 @@ public function getConfig(): array; public function isSortable(): bool; public function isEditable(): bool; -} \ No newline at end of file +} diff --git a/src/Grid/Adapter/IntegerColumnAdapter.php b/src/Grid/Adapter/IntegerColumnAdapter.php index deeee3e95..d9bb67a35 100644 --- a/src/Grid/Adapter/IntegerColumnAdapter.php +++ b/src/Grid/Adapter/IntegerColumnAdapter.php @@ -21,7 +21,6 @@ */ final readonly class IntegerColumnAdapter implements ColumnAdapterInterface { - public function getType(): string { return 'integer'; @@ -41,4 +40,4 @@ public function isEditable(): bool { return false; } -} \ No newline at end of file +} diff --git a/src/Grid/Mapper/ColumnMapper.php b/src/Grid/Mapper/ColumnMapper.php index eb5a10af1..283ddb3bd 100644 --- a/src/Grid/Mapper/ColumnMapper.php +++ b/src/Grid/Mapper/ColumnMapper.php @@ -31,16 +31,15 @@ 'filename' => 'string', 'creationDate' => 'datetime', 'modificationDate' => 'datetime', - 'size' => 'integer' + 'size' => 'integer', ]; - public function getType(string $column): string { - if(!array_key_exists($column, self::COLUMN_MAPPING)) { - throw new InvalidArgumentException('Column not found'); - } + if(!array_key_exists($column, self::COLUMN_MAPPING)) { + throw new InvalidArgumentException('Column not found'); + } - return self::COLUMN_MAPPING[$column]; + return self::COLUMN_MAPPING[$column]; } -} \ No newline at end of file +} diff --git a/src/Grid/Mapper/ColumnMapperInterface.php b/src/Grid/Mapper/ColumnMapperInterface.php index 9adf38c8a..257a5ccb0 100644 --- a/src/Grid/Mapper/ColumnMapperInterface.php +++ b/src/Grid/Mapper/ColumnMapperInterface.php @@ -22,4 +22,4 @@ interface ColumnMapperInterface { public function getType(string $column): string; -} \ No newline at end of file +} diff --git a/src/Grid/Schema/ColumnDefinition.php b/src/Grid/Schema/ColumnDefinition.php index 9428efcf6..acc50d133 100644 --- a/src/Grid/Schema/ColumnDefinition.php +++ b/src/Grid/Schema/ColumnDefinition.php @@ -22,6 +22,7 @@ /** * Column contains all data + values that is needed for the grid + * * @internal */ #[Schema( @@ -45,8 +46,7 @@ public function __construct( private string $type, #[Property(description: 'Config', type: 'array', items: new Items(type: 'string'), example: ['key' => 'value'])] private array $config, - ) - { + ) { } @@ -84,4 +84,4 @@ public function getType(): string { return $this->type; } -} \ No newline at end of file +} diff --git a/src/Grid/Schema/Configuration.php b/src/Grid/Schema/Configuration.php index 4ee3d2661..b780e013d 100644 --- a/src/Grid/Schema/Configuration.php +++ b/src/Grid/Schema/Configuration.php @@ -49,4 +49,4 @@ public function getColumns(): array { return $this->columns; } -} \ No newline at end of file +} diff --git a/src/Grid/Service/AdapterLoaderInterface.php b/src/Grid/Service/AdapterLoaderInterface.php index 744725d89..ade2d7322 100644 --- a/src/Grid/Service/AdapterLoaderInterface.php +++ b/src/Grid/Service/AdapterLoaderInterface.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; - use Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\ColumnAdapterInterface; /** diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index f863748d1..2cdaf6b77 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -38,14 +38,15 @@ public function __construct( ) { $this->adapters = $adapterLoader->loadAdapters(); } + public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array { - // $data = []; - // foreach($configuration->getColumns() as $column) { - // $data[$column->getKey()] = $column->getData($element); - // } + // $data = []; + // foreach($configuration->getColumns() as $column) { + // $data[$column->getKey()] = $column->getData($element); + // } - // return $data; + // return $data; return []; } @@ -67,6 +68,7 @@ public function getAssetGridConfiguration(): Configuration config: $this->adapters[$type]->getConfig() ); } + return new Configuration($columns); } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 331423110..0af09ca9e 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -26,9 +26,10 @@ interface GridServiceInterface { public function getAssetGridConfiguration(): Configuration; + public function getDocumentGridColumns(): Configuration; public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration; public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array; -} \ No newline at end of file +} diff --git a/src/Grid/Service/Loader/TaggedIteratorAdapter.php b/src/Grid/Service/Loader/TaggedIteratorAdapter.php index a95f0eec2..f2d4c413a 100644 --- a/src/Grid/Service/Loader/TaggedIteratorAdapter.php +++ b/src/Grid/Service/Loader/TaggedIteratorAdapter.php @@ -43,8 +43,9 @@ public function loadAdapters(): array { $adapters = []; foreach($this->taggedAdapter as $adapter) { - $adapters[$adapter->getType()] = $adapter; + $adapters[$adapter->getType()] = $adapter; } + return $adapters; } } diff --git a/src/Grid/Service/SystemColumnService.php b/src/Grid/Service/SystemColumnService.php index b9e6a18d6..65f69e670 100644 --- a/src/Grid/Service/SystemColumnService.php +++ b/src/Grid/Service/SystemColumnService.php @@ -39,4 +39,4 @@ public function getSystemColumnsForAssets(): array return $columns; } -} \ No newline at end of file +} diff --git a/src/Grid/Service/SystemColumnServiceInterface.php b/src/Grid/Service/SystemColumnServiceInterface.php index 557ed0aec..bfaafef8b 100644 --- a/src/Grid/Service/SystemColumnServiceInterface.php +++ b/src/Grid/Service/SystemColumnServiceInterface.php @@ -22,4 +22,4 @@ interface SystemColumnServiceInterface { public function getSystemColumnsForAssets(): array; -} \ No newline at end of file +} From bb716402195fce314e717278c8a73abac5c098de Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 14:26:59 +0200 Subject: [PATCH 03/22] Consistency check --- src/Grid/Mapper/ColumnMapper.php | 2 +- src/Grid/Service/GridService.php | 4 ++-- src/Grid/Service/Loader/TaggedIteratorAdapter.php | 6 +++--- src/Grid/Service/SystemColumnService.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Grid/Mapper/ColumnMapper.php b/src/Grid/Mapper/ColumnMapper.php index 283ddb3bd..9413bf862 100644 --- a/src/Grid/Mapper/ColumnMapper.php +++ b/src/Grid/Mapper/ColumnMapper.php @@ -36,7 +36,7 @@ public function getType(string $column): string { - if(!array_key_exists($column, self::COLUMN_MAPPING)) { + if (!array_key_exists($column, self::COLUMN_MAPPING)) { throw new InvalidArgumentException('Column not found'); } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 2cdaf6b77..159ae312a 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -54,8 +54,8 @@ public function getAssetGridConfiguration(): Configuration { $systemColumns = $this->systemColumnService->getSystemColumnsForAssets(); $columns = []; - foreach($systemColumns as $columnKey => $type) { - if(!array_key_exists($type, $this->adapters)) { + foreach ($systemColumns as $columnKey => $type) { + if (!array_key_exists($type, $this->adapters)) { continue; } $columns[] = new ColumnDefinition( diff --git a/src/Grid/Service/Loader/TaggedIteratorAdapter.php b/src/Grid/Service/Loader/TaggedIteratorAdapter.php index f2d4c413a..3300961d4 100644 --- a/src/Grid/Service/Loader/TaggedIteratorAdapter.php +++ b/src/Grid/Service/Loader/TaggedIteratorAdapter.php @@ -32,17 +32,17 @@ */ public function __construct( #[TaggedIterator(self::ADAPTER_TAG)] - private readonly iterable $taggedAdapter, + private iterable $taggedAdapter, ) { } /** - * @return array + * @return array */ public function loadAdapters(): array { $adapters = []; - foreach($this->taggedAdapter as $adapter) { + foreach ($this->taggedAdapter as $adapter) { $adapters[$adapter->getType()] = $adapter; } diff --git a/src/Grid/Service/SystemColumnService.php b/src/Grid/Service/SystemColumnService.php index 65f69e670..bb95662e5 100644 --- a/src/Grid/Service/SystemColumnService.php +++ b/src/Grid/Service/SystemColumnService.php @@ -33,7 +33,7 @@ public function getSystemColumnsForAssets(): array { $systemColumns = Service::GRID_SYSTEM_COLUMNS; $columns = []; - foreach($systemColumns as $column) { + foreach ($systemColumns as $column) { $columns[$column] = $this->columnMapper->getType($column); } From da65413cddd43bc51e7d22696af147998791ed8a Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 14:32:47 +0200 Subject: [PATCH 04/22] Change type in interface --- src/Grid/Service/AdapterLoaderInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Service/AdapterLoaderInterface.php b/src/Grid/Service/AdapterLoaderInterface.php index ade2d7322..4e924fa5e 100644 --- a/src/Grid/Service/AdapterLoaderInterface.php +++ b/src/Grid/Service/AdapterLoaderInterface.php @@ -24,7 +24,7 @@ interface AdapterLoaderInterface { /** - * @return array + * @return array */ public function loadAdapters(): array; } From 5d4dbd185a5b9a4cd771e371afc8ba56ba0180d8 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 14:46:10 +0200 Subject: [PATCH 05/22] Add adapters --- config/grid.yaml | 7 ++++ src/Grid/Adapter/DatetimeColumnAdapter.php | 43 ++++++++++++++++++++++ src/Grid/Adapter/ImageColumnAdapter.php | 43 ++++++++++++++++++++++ src/Grid/Adapter/StringColumnAdapter.php | 43 ++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 src/Grid/Adapter/DatetimeColumnAdapter.php create mode 100644 src/Grid/Adapter/ImageColumnAdapter.php create mode 100644 src/Grid/Adapter/StringColumnAdapter.php diff --git a/config/grid.yaml b/config/grid.yaml index 1cf5a7e6f..c4a43d7bc 100644 --- a/config/grid.yaml +++ b/config/grid.yaml @@ -22,3 +22,10 @@ services: Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\IntegerColumnAdapter: tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\StringColumnAdapter: + tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\DatetimeColumnAdapter: + tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + diff --git a/src/Grid/Adapter/DatetimeColumnAdapter.php b/src/Grid/Adapter/DatetimeColumnAdapter.php new file mode 100644 index 000000000..aab93798f --- /dev/null +++ b/src/Grid/Adapter/DatetimeColumnAdapter.php @@ -0,0 +1,43 @@ + Date: Mon, 1 Jul 2024 17:06:43 +0200 Subject: [PATCH 06/22] Add resolvers --- config/grid.yaml | 45 +++++++++++--- .../CompilerPass/GridColumnDefinitionPass.php | 49 +++++++++++++++ ...terPass.php => GridColumnResolverPass.php} | 10 +-- .../ColumnDefinitionInterface.php} | 6 +- src/Grid/Column/ColumnResolverInterface.php | 27 ++++++++ .../Definition/DatetimeDefinition.php} | 11 ++-- .../Column/Definition/FileSizeDefinition.php | 40 ++++++++++++ .../Definition/ImageDefinition.php} | 11 ++-- .../Definition/IntegerDefinition.php} | 11 ++-- .../Definition/StringDefinition.php} | 11 ++-- src/Grid/Column/Resolver/DatetimeResolver.php | 40 ++++++++++++ src/Grid/Column/Resolver/FileSizeResolver.php | 40 ++++++++++++ src/Grid/Column/Resolver/ImageResolver.php | 41 +++++++++++++ src/Grid/Column/Resolver/IntegerResolver.php | 39 ++++++++++++ src/Grid/Column/Resolver/StringResolver.php | 39 ++++++++++++ src/Grid/Mapper/ColumnMapper.php | 2 +- .../{ColumnDefinition.php => Column.php} | 2 +- src/Grid/Schema/Configuration.php | 6 +- .../ColumnDefinitionLoaderInterface.php | 30 +++++++++ ....php => ColumnResolverLoaderInterface.php} | 8 +-- src/Grid/Service/GridService.php | 61 +++++++++++++------ src/Grid/Service/GridServiceInterface.php | 2 + .../Service/Loader/TaggedIteratorAdapter.php | 51 ---------------- .../TaggedIteratorColumnDefinitionLoader.php | 51 ++++++++++++++++ .../TaggedIteratorColumnResolverLoader.php | 52 ++++++++++++++++ src/PimcoreStudioBackendBundle.php | 4 ++ 26 files changed, 566 insertions(+), 123 deletions(-) create mode 100644 src/DependencyInjection/CompilerPass/GridColumnDefinitionPass.php rename src/DependencyInjection/CompilerPass/{GridColumnAdapterPass.php => GridColumnResolverPass.php} (81%) rename src/Grid/{Adapter/ColumnAdapterInterface.php => Column/ColumnDefinitionInterface.php} (81%) create mode 100644 src/Grid/Column/ColumnResolverInterface.php rename src/Grid/{Adapter/DatetimeColumnAdapter.php => Column/Definition/DatetimeDefinition.php} (75%) create mode 100644 src/Grid/Column/Definition/FileSizeDefinition.php rename src/Grid/{Adapter/ImageColumnAdapter.php => Column/Definition/ImageDefinition.php} (77%) rename src/Grid/{Adapter/IntegerColumnAdapter.php => Column/Definition/IntegerDefinition.php} (75%) rename src/Grid/{Adapter/StringColumnAdapter.php => Column/Definition/StringDefinition.php} (76%) create mode 100644 src/Grid/Column/Resolver/DatetimeResolver.php create mode 100644 src/Grid/Column/Resolver/FileSizeResolver.php create mode 100644 src/Grid/Column/Resolver/ImageResolver.php create mode 100644 src/Grid/Column/Resolver/IntegerResolver.php create mode 100644 src/Grid/Column/Resolver/StringResolver.php rename src/Grid/Schema/{ColumnDefinition.php => Column.php} (98%) create mode 100644 src/Grid/Service/ColumnDefinitionLoaderInterface.php rename src/Grid/Service/{AdapterLoaderInterface.php => ColumnResolverLoaderInterface.php} (73%) delete mode 100644 src/Grid/Service/Loader/TaggedIteratorAdapter.php create mode 100644 src/Grid/Service/Loader/TaggedIteratorColumnDefinitionLoader.php create mode 100644 src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php diff --git a/config/grid.yaml b/config/grid.yaml index c4a43d7bc..8ad6e7715 100644 --- a/config/grid.yaml +++ b/config/grid.yaml @@ -13,19 +13,46 @@ services: Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnService - Pimcore\Bundle\StudioBackendBundle\Grid\Service\AdapterLoaderInterface: - class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorAdapter + Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnDefinitionLoaderInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnDefinitionLoader + + Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnResolverLoaderInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnResolverLoader + + # + # Column Definitions + # + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\IntegerDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\StringDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\DatetimeDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\ImageDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\FileSizeDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] # - # Adapter + # Column Resolver # - Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\IntegerColumnAdapter: - tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\StringResolver: + tags: [ 'pimcore.studio_backend.grid_column_resolver' ] + + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\IntegerResolver: + tags: [ 'pimcore.studio_backend.grid_column_resolver' ] - Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\StringColumnAdapter: - tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\FileSizeResolver: + tags: [ 'pimcore.studio_backend.grid_column_resolver' ] - Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\DatetimeColumnAdapter: - tags: [ 'pimcore.studio_backend.grid_column_adapter' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\DatetimeResolver: + tags: [ 'pimcore.studio_backend.grid_column_resolver' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\ImageResolver: + tags: [ 'pimcore.studio_backend.grid_column_resolver' ] \ No newline at end of file diff --git a/src/DependencyInjection/CompilerPass/GridColumnDefinitionPass.php b/src/DependencyInjection/CompilerPass/GridColumnDefinitionPass.php new file mode 100644 index 000000000..436cc9797 --- /dev/null +++ b/src/DependencyInjection/CompilerPass/GridColumnDefinitionPass.php @@ -0,0 +1,49 @@ +findTaggedServiceIds(TaggedIteratorColumnDefinitionLoader::COLUMN_DEFINITION_TAG), + + ] + ); + + foreach ($taggedServices as $environmentType) { + $this->checkInterface($environmentType, ColumnDefinitionInterface::class); + } + } +} diff --git a/src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php b/src/DependencyInjection/CompilerPass/GridColumnResolverPass.php similarity index 81% rename from src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php rename to src/DependencyInjection/CompilerPass/GridColumnResolverPass.php index 1b3d09b40..1fecf4961 100644 --- a/src/DependencyInjection/CompilerPass/GridColumnAdapterPass.php +++ b/src/DependencyInjection/CompilerPass/GridColumnResolverPass.php @@ -17,8 +17,8 @@ namespace Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass; use Pimcore\Bundle\StudioBackendBundle\Exception\MustImplementInterfaceException; -use Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\ColumnAdapterInterface; -use Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorAdapter; +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnResolverLoader; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\MustImplementInterfaceTrait; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -26,7 +26,7 @@ /** * @internal */ -final readonly class GridColumnAdapterPass implements CompilerPassInterface +final readonly class GridColumnResolverPass implements CompilerPassInterface { use MustImplementInterfaceTrait; @@ -37,13 +37,13 @@ public function process(ContainerBuilder $container): void { $taggedServices = array_keys( [ - ... $container->findTaggedServiceIds(TaggedIteratorAdapter::ADAPTER_TAG), + ... $container->findTaggedServiceIds(TaggedIteratorColumnResolverLoader::COLUMN_RESOLVER_TAG), ] ); foreach ($taggedServices as $environmentType) { - $this->checkInterface($environmentType, ColumnAdapterInterface::class); + $this->checkInterface($environmentType, ColumnResolverInterface::class); } } } diff --git a/src/Grid/Adapter/ColumnAdapterInterface.php b/src/Grid/Column/ColumnDefinitionInterface.php similarity index 81% rename from src/Grid/Adapter/ColumnAdapterInterface.php rename to src/Grid/Column/ColumnDefinitionInterface.php index 59c8bf091..c82cf7adb 100644 --- a/src/Grid/Adapter/ColumnAdapterInterface.php +++ b/src/Grid/Column/ColumnDefinitionInterface.php @@ -14,18 +14,16 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Grid\Adapter; +namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column; /** * @internal */ -interface ColumnAdapterInterface +interface ColumnDefinitionInterface { public function getType(): string; public function getConfig(): array; public function isSortable(): bool; - - public function isEditable(): bool; } diff --git a/src/Grid/Column/ColumnResolverInterface.php b/src/Grid/Column/ColumnResolverInterface.php new file mode 100644 index 000000000..fc0aad5b2 --- /dev/null +++ b/src/Grid/Column/ColumnResolverInterface.php @@ -0,0 +1,27 @@ +getKey()); + return Carbon::create($element->$getter())->toISOString(); + } + + public function getType(): string + { + return 'datetime'; + } +} \ No newline at end of file diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php new file mode 100644 index 000000000..0e8d2c101 --- /dev/null +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -0,0 +1,40 @@ +getFileSize(true); + } + + public function getType(): string + { + return 'fileSize'; + } +} \ No newline at end of file diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php new file mode 100644 index 000000000..6368f4e6b --- /dev/null +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -0,0 +1,41 @@ +getRealFullPath(); + } + + public function getType(): string + { + return 'image'; + } +} \ No newline at end of file diff --git a/src/Grid/Column/Resolver/IntegerResolver.php b/src/Grid/Column/Resolver/IntegerResolver.php new file mode 100644 index 000000000..f271408a5 --- /dev/null +++ b/src/Grid/Column/Resolver/IntegerResolver.php @@ -0,0 +1,39 @@ +getKey()); + return $element->$getter(); + } + + public function getType(): string + { + return 'integer'; + } +} \ No newline at end of file diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php new file mode 100644 index 000000000..310466218 --- /dev/null +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -0,0 +1,39 @@ +getKey()); + return $element->$getter(); + } + + public function getType(): string + { + return 'string'; + } +} \ No newline at end of file diff --git a/src/Grid/Mapper/ColumnMapper.php b/src/Grid/Mapper/ColumnMapper.php index 9413bf862..1aa64acfd 100644 --- a/src/Grid/Mapper/ColumnMapper.php +++ b/src/Grid/Mapper/ColumnMapper.php @@ -31,7 +31,7 @@ 'filename' => 'string', 'creationDate' => 'datetime', 'modificationDate' => 'datetime', - 'size' => 'integer', + 'size' => 'fileSize', ]; public function getType(string $column): string diff --git a/src/Grid/Schema/ColumnDefinition.php b/src/Grid/Schema/Column.php similarity index 98% rename from src/Grid/Schema/ColumnDefinition.php rename to src/Grid/Schema/Column.php index acc50d133..b025617a5 100644 --- a/src/Grid/Schema/ColumnDefinition.php +++ b/src/Grid/Schema/Column.php @@ -29,7 +29,7 @@ title: 'GridColumnDefinition', type: 'object' )] -final readonly class ColumnDefinition +final readonly class Column { public function __construct( #[Property(description: 'Key', type: 'string', example: 'id')] diff --git a/src/Grid/Schema/Configuration.php b/src/Grid/Schema/Configuration.php index b780e013d..685884fad 100644 --- a/src/Grid/Schema/Configuration.php +++ b/src/Grid/Schema/Configuration.php @@ -30,20 +30,20 @@ final readonly class Configuration { /** - * @param array $columns + * @param array $columns */ public function __construct( #[Property( property: 'columns', type: 'array', - items: new Items(ref: ColumnDefinition::class) + items: new Items(ref: Column::class) )] private array $columns, ) { } /** - * @return array + * @return array */ public function getColumns(): array { diff --git a/src/Grid/Service/ColumnDefinitionLoaderInterface.php b/src/Grid/Service/ColumnDefinitionLoaderInterface.php new file mode 100644 index 000000000..8f1413ba3 --- /dev/null +++ b/src/Grid/Service/ColumnDefinitionLoaderInterface.php @@ -0,0 +1,30 @@ + + */ + public function loadColumnDefinitions(): array; +} diff --git a/src/Grid/Service/AdapterLoaderInterface.php b/src/Grid/Service/ColumnResolverLoaderInterface.php similarity index 73% rename from src/Grid/Service/AdapterLoaderInterface.php rename to src/Grid/Service/ColumnResolverLoaderInterface.php index 4e924fa5e..a4df23a79 100644 --- a/src/Grid/Service/AdapterLoaderInterface.php +++ b/src/Grid/Service/ColumnResolverLoaderInterface.php @@ -16,15 +16,15 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; -use Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\ColumnAdapterInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; /** * @internal */ -interface AdapterLoaderInterface +interface ColumnResolverLoaderInterface { /** - * @return array + * @return array */ - public function loadAdapters(): array; + public function loadColumnResolvers(): array; } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 159ae312a..8525ef8d8 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -16,8 +16,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; -use Pimcore\Bundle\StudioBackendBundle\Grid\Adapter\ColumnAdapterInterface; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnDefinition; +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -28,26 +29,34 @@ final readonly class GridService implements GridServiceInterface { /** - * @param array $adapters + * @param array $columnDefinitions */ - private array $adapters; + private array $columnDefinitions; + + /** + * @param array $columnResolvers + */ + private array $columnResolvers; public function __construct( - AdapterLoaderInterface $adapterLoader, + ColumnDefinitionLoaderInterface $columnAdapterLoader, + ColumnResolverLoaderInterface $columnResolverLoader, private SystemColumnServiceInterface $systemColumnService ) { - $this->adapters = $adapterLoader->loadAdapters(); + $this->columnDefinitions = $columnAdapterLoader->loadColumnDefinitions(); + $this->columnResolvers = $columnResolverLoader->loadColumnResolvers(); } public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array { - // $data = []; - // foreach($configuration->getColumns() as $column) { - // $data[$column->getKey()] = $column->getData($element); - // } - - // return $data; - return []; + $data = []; + foreach($configuration->getColumns() as $column) { + if(!array_key_exists($column->getType(), $this->columnResolvers)) { + continue; + } + $data[$column->getKey()] = $this->columnResolvers[$column->getType()]->resolve($column, $element); + } + return $data; } public function getAssetGridConfiguration(): Configuration @@ -55,17 +64,17 @@ public function getAssetGridConfiguration(): Configuration $systemColumns = $this->systemColumnService->getSystemColumnsForAssets(); $columns = []; foreach ($systemColumns as $columnKey => $type) { - if (!array_key_exists($type, $this->adapters)) { + if (!array_key_exists($type, $this->columnDefinitions)) { continue; } - $columns[] = new ColumnDefinition( + $columns[] = new Column( key: $columnKey, group: 'system', - sortable: $this->adapters[$type]->isSortable(), + sortable: $this->columnDefinitions[$type]->isSortable(), editable: false, localizable: false, type: $type, - config: $this->adapters[$type]->getConfig() + config: $this->columnDefinitions[$type]->getConfig() ); } @@ -81,4 +90,22 @@ public function getDataObjectGridColumns(ClassDefinition $classDefinition): Conf { return new Configuration([]); } + + public function getConfigurationFromArray(array $config): Configuration + { + $columns = []; + + foreach ($config['columns'] as $column) { + $columns[] = new Column( + key: $column['key'], + group: $column['group'], + sortable: $column['sortable'], + editable: $column['editable'], + localizable: $column['localizable'], + type: $column['type'], + config: $column['config'] + ); + } + return new Configuration($columns); + } } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 0af09ca9e..3f3bef2b8 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -32,4 +32,6 @@ public function getDocumentGridColumns(): Configuration; public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration; public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array; + + public function getConfigurationFromArray(array $config): Configuration; } diff --git a/src/Grid/Service/Loader/TaggedIteratorAdapter.php b/src/Grid/Service/Loader/TaggedIteratorAdapter.php deleted file mode 100644 index 3300961d4..000000000 --- a/src/Grid/Service/Loader/TaggedIteratorAdapter.php +++ /dev/null @@ -1,51 +0,0 @@ - $taggedAdapter - */ - public function __construct( - #[TaggedIterator(self::ADAPTER_TAG)] - private iterable $taggedAdapter, - ) { - } - - /** - * @return array - */ - public function loadAdapters(): array - { - $adapters = []; - foreach ($this->taggedAdapter as $adapter) { - $adapters[$adapter->getType()] = $adapter; - } - - return $adapters; - } -} diff --git a/src/Grid/Service/Loader/TaggedIteratorColumnDefinitionLoader.php b/src/Grid/Service/Loader/TaggedIteratorColumnDefinitionLoader.php new file mode 100644 index 000000000..f6b022b3e --- /dev/null +++ b/src/Grid/Service/Loader/TaggedIteratorColumnDefinitionLoader.php @@ -0,0 +1,51 @@ + $taggedColumnDefinitions + */ + public function __construct( + #[TaggedIterator(self::COLUMN_DEFINITION_TAG)] + private iterable $taggedColumnDefinitions, + ) { + } + + /** + * @return array + */ + public function loadColumnDefinitions(): array + { + $columnDefinitions = []; + foreach ($this->taggedColumnDefinitions as $columnDefinition) { + $columnDefinitions[$columnDefinition->getType()] = $columnDefinition; + } + + return $columnDefinitions; + } +} diff --git a/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php new file mode 100644 index 000000000..512f4087a --- /dev/null +++ b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php @@ -0,0 +1,52 @@ + $taggedColumnResolvers + */ + public function __construct( + #[TaggedIterator(self::COLUMN_RESOLVER_TAG)] + private iterable $taggedColumnResolvers, + ) { + } + + /** + * @return array + */ + public function loadColumnResolvers(): array + { + $columnResolvers = []; + foreach ($this->taggedColumnResolvers as $columnResolver) { + $columnResolvers[$columnResolver->getType()] = $columnResolver; + } + + return $columnResolvers; + } +} diff --git a/src/PimcoreStudioBackendBundle.php b/src/PimcoreStudioBackendBundle.php index 5644a8620..7d92ad74a 100644 --- a/src/PimcoreStudioBackendBundle.php +++ b/src/PimcoreStudioBackendBundle.php @@ -20,6 +20,8 @@ use Pimcore\Bundle\GenericExecutionEngineBundle\PimcoreGenericExecutionEngineBundle; use Pimcore\Bundle\StaticResolverBundle\PimcoreStaticResolverBundle; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\FilterPass; +use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\GridColumnDefinitionPass; +use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\GridColumnResolverPass; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\MercureTopicsProviderPass; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\PatchAdapterPass; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\SettingsProviderPass; @@ -70,6 +72,8 @@ public function build(ContainerBuilder $container): void { $container->addCompilerPass(new FilterPass()); $container->addCompilerPass(new PatchAdapterPass()); + $container->addCompilerPass(new GridColumnDefinitionPass()); + $container->addCompilerPass(new GridColumnResolverPass()); $container->addCompilerPass(new UpdateAdapterPass()); $container->addCompilerPass(new SettingsProviderPass()); $container->addCompilerPass(new MercureTopicsProviderPass()); From 7418d365621229b91625566c3ef1b53b520ee931 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 15:07:08 +0000 Subject: [PATCH 07/22] Apply php-cs-fixer changes --- src/Grid/Column/ColumnResolverInterface.php | 2 +- src/Grid/Column/Resolver/DatetimeResolver.php | 4 ++-- src/Grid/Column/Resolver/FileSizeResolver.php | 3 +-- src/Grid/Column/Resolver/ImageResolver.php | 4 +--- src/Grid/Column/Resolver/IntegerResolver.php | 4 ++-- src/Grid/Column/Resolver/StringResolver.php | 4 ++-- src/Grid/Service/GridService.php | 18 ++++++++++-------- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Grid/Column/ColumnResolverInterface.php b/src/Grid/Column/ColumnResolverInterface.php index fc0aad5b2..f07174c85 100644 --- a/src/Grid/Column/ColumnResolverInterface.php +++ b/src/Grid/Column/ColumnResolverInterface.php @@ -24,4 +24,4 @@ interface ColumnResolverInterface public function resolve(Column $columnDefinition, ElementInterface $element): mixed; public function getType(): string; -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/DatetimeResolver.php b/src/Grid/Column/Resolver/DatetimeResolver.php index 3d32d498e..f6af6157d 100644 --- a/src/Grid/Column/Resolver/DatetimeResolver.php +++ b/src/Grid/Column/Resolver/DatetimeResolver.php @@ -26,10 +26,10 @@ */ final class DatetimeResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed { $getter = 'get' . ucfirst($columnDefinition->getKey()); + return Carbon::create($element->$getter())->toISOString(); } @@ -37,4 +37,4 @@ public function getType(): string { return 'datetime'; } -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index 0e8d2c101..f9303353b 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -26,7 +26,6 @@ */ final class FileSizeResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed { /** @var Asset $element */ @@ -37,4 +36,4 @@ public function getType(): string { return 'fileSize'; } -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php index 6368f4e6b..c03203302 100644 --- a/src/Grid/Column/Resolver/ImageResolver.php +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -16,8 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; -use Carbon\Carbon; -use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ThumbnailServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Model\Asset; @@ -38,4 +36,4 @@ public function getType(): string { return 'image'; } -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/IntegerResolver.php b/src/Grid/Column/Resolver/IntegerResolver.php index f271408a5..dd8c37402 100644 --- a/src/Grid/Column/Resolver/IntegerResolver.php +++ b/src/Grid/Column/Resolver/IntegerResolver.php @@ -25,10 +25,10 @@ */ final class IntegerResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed { $getter = 'get' . ucfirst($columnDefinition->getKey()); + return $element->$getter(); } @@ -36,4 +36,4 @@ public function getType(): string { return 'integer'; } -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php index 310466218..d88f4b2fa 100644 --- a/src/Grid/Column/Resolver/StringResolver.php +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -25,10 +25,10 @@ */ final class StringResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed { $getter = 'get' . ucfirst($columnDefinition->getKey()); + return $element->$getter(); } @@ -36,4 +36,4 @@ public function getType(): string { return 'string'; } -} \ No newline at end of file +} diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 8525ef8d8..c299e45d2 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -49,14 +49,15 @@ public function __construct( public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array { - $data = []; - foreach($configuration->getColumns() as $column) { - if(!array_key_exists($column->getType(), $this->columnResolvers)) { - continue; - } - $data[$column->getKey()] = $this->columnResolvers[$column->getType()]->resolve($column, $element); - } - return $data; + $data = []; + foreach($configuration->getColumns() as $column) { + if(!array_key_exists($column->getType(), $this->columnResolvers)) { + continue; + } + $data[$column->getKey()] = $this->columnResolvers[$column->getType()]->resolve($column, $element); + } + + return $data; } public function getAssetGridConfiguration(): Configuration @@ -106,6 +107,7 @@ public function getConfigurationFromArray(array $config): Configuration config: $column['config'] ); } + return new Configuration($columns); } } From 448c393cc3367fb8d654b5ce1c11e2c6f1891ffe Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 17:10:33 +0200 Subject: [PATCH 08/22] Return ColumnResolverInterface --- src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php index 512f4087a..7c4417d9a 100644 --- a/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php +++ b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php @@ -38,7 +38,7 @@ public function __construct( } /** - * @return array + * @return array */ public function loadColumnResolvers(): array { From 0c0478760a0fd01edb1a406c1d86cf544c20cefc Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 1 Jul 2024 15:11:00 +0000 Subject: [PATCH 09/22] Apply php-cs-fixer changes --- src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php index 7c4417d9a..abde3a26a 100644 --- a/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php +++ b/src/Grid/Service/Loader/TaggedIteratorColumnResolverLoader.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader; -use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnResolverLoaderInterface; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; From e7a2141a0d1ddaa34d8a222a4c3215d19b403a94 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 10:31:40 +0200 Subject: [PATCH 10/22] Add GridSearch --- config/grid.yaml | 5 ++ .../Grid/Configuration/GetController.php | 2 +- src/Asset/Controller/Grid/GetController.php | 80 +++++++++++++++++++ src/DataIndex/Grid/GridSearch.php | 45 +++++++++++ src/DataIndex/Grid/GridSearchInterface.php | 29 +++++++ src/Grid/Column/ColumnResolverInterface.php | 2 + src/Grid/Column/Resolver/DatetimeResolver.php | 16 +++- src/Grid/Column/Resolver/FileSizeResolver.php | 10 ++- src/Grid/Column/Resolver/ImageResolver.php | 12 ++- src/Grid/Column/Resolver/IntegerResolver.php | 19 ++++- src/Grid/Column/Resolver/StringResolver.php | 18 ++++- src/Grid/MappedParameter/GridParameter.php | 41 ++++++++++ src/Grid/Schema/ColumnData.php | 56 +++++++++++++ src/Grid/Service/GridService.php | 67 ++++++++++++++-- src/Grid/Service/GridServiceInterface.php | 6 +- src/Grid/Util/Trait/SimpleGetterTrait.php | 46 +++++++++++ src/OpenApi/Config/Tags.php | 5 ++ 17 files changed, 440 insertions(+), 19 deletions(-) create mode 100644 src/Asset/Controller/Grid/GetController.php create mode 100644 src/DataIndex/Grid/GridSearch.php create mode 100644 src/DataIndex/Grid/GridSearchInterface.php create mode 100644 src/Grid/MappedParameter/GridParameter.php create mode 100644 src/Grid/Schema/ColumnData.php create mode 100644 src/Grid/Util/Trait/SimpleGetterTrait.php diff --git a/config/grid.yaml b/config/grid.yaml index 8ad6e7715..082984206 100644 --- a/config/grid.yaml +++ b/config/grid.yaml @@ -4,6 +4,11 @@ services: autoconfigure: true public: false + + Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface: + class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearch + + Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapperInterface: class: Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapper diff --git a/src/Asset/Controller/Grid/Configuration/GetController.php b/src/Asset/Controller/Grid/Configuration/GetController.php index 8fc5e066d..b0bf82665 100644 --- a/src/Asset/Controller/Grid/Configuration/GetController.php +++ b/src/Asset/Controller/Grid/Configuration/GetController.php @@ -55,7 +55,7 @@ public function __construct( operationId: 'getAssetGridConfiguration', description: 'Get assets grid configuration', summary: 'Get default assets grid configuration', - tags: [Tags::Assets->name] + tags: [Tags::Grid->name] )] #[SuccessResponse( description: 'Grid configuration', diff --git a/src/Asset/Controller/Grid/GetController.php b/src/Asset/Controller/Grid/GetController.php new file mode 100644 index 000000000..679344bcd --- /dev/null +++ b/src/Asset/Controller/Grid/GetController.php @@ -0,0 +1,80 @@ +value)] + #[Post( + path: self::API_PATH . '/assets/grid', + operationId: 'getAssetGrid', + description: 'Get assets for grid', + summary: 'Get assets for grid', + tags: [Tags::Grid->name] + )] + #[RequestBody( + content: new JsonContent(ref: GridParameter::class) + )] + #[SuccessResponse( + description: 'Grid data', + content: new JsonContent( + ref: Configuration::class + ) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + ])] + public function getAssetGrid(#[MapRequestPayload] GridParameter $gridParameter): JsonResponse + { + return $this->jsonResponse($this->gridService->getAssetGrid($gridParameter)); + } +} diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php new file mode 100644 index 000000000..6904b6d80 --- /dev/null +++ b/src/DataIndex/Grid/GridSearch.php @@ -0,0 +1,45 @@ +setUser($this->securityService->getCurrentUser()); + + return $this->assetSearchService->search($search); + } +} \ No newline at end of file diff --git a/src/DataIndex/Grid/GridSearchInterface.php b/src/DataIndex/Grid/GridSearchInterface.php new file mode 100644 index 000000000..d8db1cde2 --- /dev/null +++ b/src/DataIndex/Grid/GridSearchInterface.php @@ -0,0 +1,29 @@ +getKey()); + $getter = $this->getGetter($columnDefinition); return Carbon::create($element->$getter())->toISOString(); } @@ -37,4 +40,13 @@ public function getType(): string { return 'datetime'; } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ElementTypes::TYPE_DOCUMENT, + ElementTypes::TYPE_OBJECT, + ]; + } } diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index f9303353b..f94af3e08 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Asset; use Pimcore\Model\Element\ElementInterface; @@ -26,7 +27,7 @@ */ final class FileSizeResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed + public function resolve(Column $columnDefinition, ElementInterface $element): string|int { /** @var Asset $element */ return $element->getFileSize(true); @@ -36,4 +37,11 @@ public function getType(): string { return 'fileSize'; } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ]; + } } diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php index c03203302..1b8f9c999 100644 --- a/src/Grid/Column/Resolver/ImageResolver.php +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Asset; use Pimcore\Model\Element\ElementInterface; @@ -26,7 +27,7 @@ */ final class ImageResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed + public function resolve(Column $columnDefinition, ElementInterface $element): string { /** @var Asset $element */ return $element->getRealFullPath(); @@ -36,4 +37,13 @@ public function getType(): string { return 'image'; } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ElementTypes::TYPE_DOCUMENT, + ElementTypes::TYPE_OBJECT, + ]; + } } diff --git a/src/Grid/Column/Resolver/IntegerResolver.php b/src/Grid/Column/Resolver/IntegerResolver.php index dd8c37402..1d72c0cb1 100644 --- a/src/Grid/Column/Resolver/IntegerResolver.php +++ b/src/Grid/Column/Resolver/IntegerResolver.php @@ -18,6 +18,8 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\SimpleGetterTrait; +use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Element\ElementInterface; /** @@ -25,15 +27,24 @@ */ final class IntegerResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed - { - $getter = 'get' . ucfirst($columnDefinition->getKey()); + use SimpleGetterTrait; - return $element->$getter(); + public function resolve(Column $columnDefinition, ElementInterface $element): int + { + return $this->getValue($columnDefinition, $element); } public function getType(): string { return 'integer'; } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ElementTypes::TYPE_DOCUMENT, + ElementTypes::TYPE_OBJECT, + ]; + } } diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php index d88f4b2fa..1603c38d5 100644 --- a/src/Grid/Column/Resolver/StringResolver.php +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -18,6 +18,8 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\SimpleGetterTrait; +use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Element\ElementInterface; /** @@ -25,15 +27,23 @@ */ final class StringResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): mixed + use SimpleGetterTrait; + public function resolve(Column $columnDefinition, ElementInterface $element): ?string { - $getter = 'get' . ucfirst($columnDefinition->getKey()); - - return $element->$getter(); + return $this->getValue($columnDefinition, $element); } public function getType(): string { return 'string'; } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ElementTypes::TYPE_DOCUMENT, + ElementTypes::TYPE_OBJECT, + ]; + } } diff --git a/src/Grid/MappedParameter/GridParameter.php b/src/Grid/MappedParameter/GridParameter.php new file mode 100644 index 000000000..c65bc6d6d --- /dev/null +++ b/src/Grid/MappedParameter/GridParameter.php @@ -0,0 +1,41 @@ +id; + } + + public function getGridConfig(): Configuration + { + return new Configuration($this->gridConfig); + } +} \ No newline at end of file diff --git a/src/Grid/Schema/ColumnData.php b/src/Grid/Schema/ColumnData.php new file mode 100644 index 000000000..8de2cd0af --- /dev/null +++ b/src/Grid/Schema/ColumnData.php @@ -0,0 +1,56 @@ +key; + } + + public function getLocale(): ?string + { + return $this->locale; + } + + public function getValue(): mixed + { + return $this->value; + } +} \ No newline at end of file diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index c299e45d2..a6b3b9765 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -16,10 +16,15 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; +use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -28,6 +33,8 @@ */ final readonly class GridService implements GridServiceInterface { + use ElementProviderTrait; + /** * @param array $columnDefinitions */ @@ -41,20 +48,54 @@ public function __construct( ColumnDefinitionLoaderInterface $columnAdapterLoader, ColumnResolverLoaderInterface $columnResolverLoader, - private SystemColumnServiceInterface $systemColumnService + private SystemColumnServiceInterface $systemColumnService, + private GridSearchInterface $gridSearch, + private ServiceResolverInterface $serviceResolver ) { $this->columnDefinitions = $columnAdapterLoader->loadColumnDefinitions(); $this->columnResolvers = $columnResolverLoader->loadColumnResolvers(); } - public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array + public function getAssetGrid(GridParameter $gridParameter): array + { + $result = $this->gridSearch->searchAssets($gridParameter); + + if(empty($result->getIds())) { + return []; + } + + $data = []; + + foreach ($result->getItems() as $item) { + $type = $item->getElementType()->value; + $asset = $this->getElement($this->serviceResolver, $type, $item->getId()); + $data[] = $this->getGridDataForElement( + $this->getAssetGridConfiguration(), + $asset, + $type + ); + } + + return ['items' => $data]; + } + + + public function getGridDataForElement( + Configuration $configuration, + ElementInterface $element, + string $elementType + ): array { $data = []; - foreach($configuration->getColumns() as $column) { - if(!array_key_exists($column->getType(), $this->columnResolvers)) { + foreach ($configuration->getColumns() as $column) { + if (!$this->supports($column, $elementType)) { continue; } - $data[$column->getKey()] = $this->columnResolvers[$column->getType()]->resolve($column, $element); + $data['columns'][] = new ColumnData( + $column->getKey(), + null, + $this->columnResolvers[$column->getType()]->resolve($column, $element) + ); } return $data; @@ -110,4 +151,20 @@ public function getConfigurationFromArray(array $config): Configuration return new Configuration($columns); } + + private function supports(Column $column, string $elementType): bool + { + if (!array_key_exists($column->getType(), $this->columnResolvers)) { + return false; + } + + /** @var ColumnResolverInterface $resolver */ + $resolver = $this->columnResolvers[$column->getType()]; + + if (!in_array($elementType, $resolver->supportedElementTypes(), true)) { + return false; + } + + return true; + } } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 3f3bef2b8..b371878d9 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -31,7 +31,11 @@ public function getDocumentGridColumns(): Configuration; public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration; - public function getGridDataForElement(Configuration $configuration, ElementInterface $element): array; + public function getGridDataForElement( + Configuration $configuration, + ElementInterface $element, + string $elementType + ): array; public function getConfigurationFromArray(array $config): Configuration; } diff --git a/src/Grid/Util/Trait/SimpleGetterTrait.php b/src/Grid/Util/Trait/SimpleGetterTrait.php new file mode 100644 index 000000000..5f9764e68 --- /dev/null +++ b/src/Grid/Util/Trait/SimpleGetterTrait.php @@ -0,0 +1,46 @@ +getKey()); + if(method_exists($element, $getter) === false) { + throw new InvalidArgumentException( + 'Method ' . $getter . ' does not exist on ' . get_class($element) + ); + } + return $element->$getter(); + } + + private function getGetter(Column $columnDefinition): string + { + return 'get' . ucfirst($columnDefinition->getKey()); + } +} \ No newline at end of file diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index c9e939b77..1000a463e 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -45,6 +45,10 @@ name: Tags::Elements->name, description: 'Get element properties for a single element based on its type and provided parameters.' )] +#[Tag( + name: Tags::Grid->name, + description: 'Grid operations' +)] #[Tag( name: Tags::Mercure->name, description: 'Retrieve JWT token for Mercure hub as cookie' @@ -93,6 +97,7 @@ enum Tags: string case DataObjects = 'DataObjects'; case Dependencies = 'Dependencies'; case Elements = 'Elements'; + case Grid = 'Grid'; case Mercure = 'Mercure'; case Notes = 'Notes'; case Properties = 'Properties'; From 3b735037d0ab1476a60ad085cacd45c0a7bc7743 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 08:32:18 +0000 Subject: [PATCH 11/22] Apply php-cs-fixer changes --- src/DataIndex/Grid/GridSearch.php | 6 ++---- src/DataIndex/Grid/GridSearchInterface.php | 3 +-- src/Grid/Column/Resolver/DatetimeResolver.php | 1 + src/Grid/Column/Resolver/StringResolver.php | 1 + src/Grid/MappedParameter/GridParameter.php | 2 +- src/Grid/Schema/ColumnData.php | 5 ++--- src/Grid/Service/GridService.php | 4 +--- src/Grid/Service/GridServiceInterface.php | 2 +- src/Grid/Util/Trait/SimpleGetterTrait.php | 3 ++- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index 6904b6d80..c24b3f3a7 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -14,7 +14,6 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ - namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearch; @@ -31,8 +30,7 @@ public function __construct( private SecurityServiceInterface $securityService, private AssetSearchServiceInterface $assetSearchService, - ) - { + ) { } public function searchAssets(GridParameter $gridParameter): AssetSearchResult @@ -42,4 +40,4 @@ public function searchAssets(GridParameter $gridParameter): AssetSearchResult return $this->assetSearchService->search($search); } -} \ No newline at end of file +} diff --git a/src/DataIndex/Grid/GridSearchInterface.php b/src/DataIndex/Grid/GridSearchInterface.php index d8db1cde2..470c18a07 100644 --- a/src/DataIndex/Grid/GridSearchInterface.php +++ b/src/DataIndex/Grid/GridSearchInterface.php @@ -14,7 +14,6 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ - namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult; @@ -26,4 +25,4 @@ interface GridSearchInterface { public function searchAssets(GridParameter $gridParameter): AssetSearchResult; -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/DatetimeResolver.php b/src/Grid/Column/Resolver/DatetimeResolver.php index 08bd354f2..704e0924f 100644 --- a/src/Grid/Column/Resolver/DatetimeResolver.php +++ b/src/Grid/Column/Resolver/DatetimeResolver.php @@ -29,6 +29,7 @@ final class DatetimeResolver implements ColumnResolverInterface { use SimpleGetterTrait; + public function resolve(Column $columnDefinition, ElementInterface $element): ?string { $getter = $this->getGetter($columnDefinition); diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php index 1603c38d5..29edf0014 100644 --- a/src/Grid/Column/Resolver/StringResolver.php +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -28,6 +28,7 @@ final class StringResolver implements ColumnResolverInterface { use SimpleGetterTrait; + public function resolve(Column $columnDefinition, ElementInterface $element): ?string { return $this->getValue($columnDefinition, $element); diff --git a/src/Grid/MappedParameter/GridParameter.php b/src/Grid/MappedParameter/GridParameter.php index c65bc6d6d..985af847f 100644 --- a/src/Grid/MappedParameter/GridParameter.php +++ b/src/Grid/MappedParameter/GridParameter.php @@ -38,4 +38,4 @@ public function getGridConfig(): Configuration { return new Configuration($this->gridConfig); } -} \ No newline at end of file +} diff --git a/src/Grid/Schema/ColumnData.php b/src/Grid/Schema/ColumnData.php index 8de2cd0af..b6c66c084 100644 --- a/src/Grid/Schema/ColumnData.php +++ b/src/Grid/Schema/ColumnData.php @@ -35,8 +35,7 @@ public function __construct( private ?string $locale, #[Property(description: 'value', type: 'mixed', example: 73)] private mixed $value - ) - { + ) { } public function getKey(): string @@ -53,4 +52,4 @@ public function getValue(): mixed { return $this->value; } -} \ No newline at end of file +} diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index a6b3b9765..92bf7db46 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -79,13 +79,11 @@ public function getAssetGrid(GridParameter $gridParameter): array return ['items' => $data]; } - public function getGridDataForElement( Configuration $configuration, ElementInterface $element, string $elementType - ): array - { + ): array { $data = []; foreach ($configuration->getColumns() as $column) { if (!$this->supports($column, $elementType)) { diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index b371878d9..9c6ab74a8 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -34,7 +34,7 @@ public function getDataObjectGridColumns(ClassDefinition $classDefinition): Conf public function getGridDataForElement( Configuration $configuration, ElementInterface $element, - string $elementType + string $elementType ): array; public function getConfigurationFromArray(array $config): Configuration; diff --git a/src/Grid/Util/Trait/SimpleGetterTrait.php b/src/Grid/Util/Trait/SimpleGetterTrait.php index 5f9764e68..a849b827f 100644 --- a/src/Grid/Util/Trait/SimpleGetterTrait.php +++ b/src/Grid/Util/Trait/SimpleGetterTrait.php @@ -36,6 +36,7 @@ private function getValue(Column $columnDefinition, ElementInterface $element): 'Method ' . $getter . ' does not exist on ' . get_class($element) ); } + return $element->$getter(); } @@ -43,4 +44,4 @@ private function getGetter(Column $columnDefinition): string { return 'get' . ucfirst($columnDefinition->getKey()); } -} \ No newline at end of file +} From 35abcd3ad7f30de84a937ec1e63f508e14f8a9ac Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 10:40:40 +0200 Subject: [PATCH 12/22] Add methods to interface --- src/DataIndex/Grid/GridSearch.php | 5 ++++- src/Grid/Service/GridServiceInterface.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index c24b3f3a7..129bc39d8 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -21,6 +21,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; +use Pimcore\Model\User; /** * @internal @@ -36,7 +37,9 @@ public function __construct( public function searchAssets(GridParameter $gridParameter): AssetSearchResult { $search = new AssetSearch(); - $search->setUser($this->securityService->getCurrentUser()); + /** @var User $user */ + $user = $this->securityService->getCurrentUser(); + $search->setUser($user); return $this->assetSearchService->search($search); } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 9c6ab74a8..d765596a4 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; +use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -38,4 +39,6 @@ public function getGridDataForElement( ): array; public function getConfigurationFromArray(array $config): Configuration; + + public function getAssetGrid(GridParameter $gridParameter): array; } From abab47c993959162c9665153067b08ecd2bb4aef Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 14:49:35 +0200 Subject: [PATCH 13/22] Adding more grid functionality --- src/Asset/Controller/Grid/GetController.php | 13 +++-- src/DataIndex/Grid/GridSearch.php | 2 + .../Attributes/Property/GridCollection.php | 44 ++++++++++++++ .../Attributes/Request/GridRequestBody.php | 57 +++++++++++++++++++ src/Grid/Column/ColumnResolverInterface.php | 3 +- src/Grid/Column/Resolver/DatetimeResolver.php | 12 ++-- src/Grid/Column/Resolver/FileSizeResolver.php | 10 +++- src/Grid/Column/Resolver/ImageResolver.php | 12 ++-- src/Grid/Column/Resolver/IntegerResolver.php | 10 +++- src/Grid/Column/Resolver/StringResolver.php | 10 +++- src/Grid/MappedParameter/GridParameter.php | 10 ++-- src/Grid/Schema/Column.php | 9 ++- src/Grid/Schema/ColumnData.php | 2 +- src/Grid/Service/GridService.php | 21 ++++--- src/Grid/Service/GridServiceInterface.php | 3 +- src/Grid/Util/Trait/ColumnDataTrait.php | 31 ++++++++++ .../Attributes/Property/SingleInteger.php | 34 +++++++++++ 17 files changed, 245 insertions(+), 38 deletions(-) create mode 100644 src/Grid/Attributes/Property/GridCollection.php create mode 100644 src/Grid/Attributes/Request/GridRequestBody.php create mode 100644 src/Grid/Util/Trait/ColumnDataTrait.php create mode 100644 src/OpenApi/Attributes/Property/SingleInteger.php diff --git a/src/Asset/Controller/Grid/GetController.php b/src/Asset/Controller/Grid/GetController.php index 679344bcd..12f2a2888 100644 --- a/src/Asset/Controller/Grid/GetController.php +++ b/src/Asset/Controller/Grid/GetController.php @@ -18,13 +18,16 @@ use OpenApi\Attributes\JsonContent; use OpenApi\Attributes\Post; -use OpenApi\Attributes\RequestBody; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Property\GridCollection; +use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Request\GridRequestBody; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Property\GenericCollection; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -60,13 +63,11 @@ public function __construct( summary: 'Get assets for grid', tags: [Tags::Grid->name] )] - #[RequestBody( - content: new JsonContent(ref: GridParameter::class) - )] + #[GridRequestBody] #[SuccessResponse( description: 'Grid data', - content: new JsonContent( - ref: Configuration::class + content: new CollectionJson( + collection: new GridCollection() ) )] #[DefaultResponses([ diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index 129bc39d8..e19441e29 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter; use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; @@ -40,6 +41,7 @@ public function searchAssets(GridParameter $gridParameter): AssetSearchResult /** @var User $user */ $user = $this->securityService->getCurrentUser(); $search->setUser($user); + $search->addModifier(new ParentIdFilter($gridParameter->getFolderId())); return $this->assetSearchService->search($search); } diff --git a/src/Grid/Attributes/Property/GridCollection.php b/src/Grid/Attributes/Property/GridCollection.php new file mode 100644 index 000000000..70ca983b2 --- /dev/null +++ b/src/Grid/Attributes/Property/GridCollection.php @@ -0,0 +1,44 @@ +getGetter($columnDefinition); - - return Carbon::create($element->$getter())->toISOString(); + return $this->getColumnData( + $column, + Carbon::create($this->getValue($column, $element))->toISOString() + ); } public function getType(): string diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index f94af3e08..9a53d574f 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -18,6 +18,8 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\ColumnDataTrait; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Asset; use Pimcore\Model\Element\ElementInterface; @@ -27,10 +29,14 @@ */ final class FileSizeResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): string|int + use ColumnDataTrait; + public function resolve(Column $column, ElementInterface $element): ColumnData { /** @var Asset $element */ - return $element->getFileSize(true); + return $this->getColumnData( + $column, + $element->getFileSize(true) + ); } public function getType(): string diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php index 1b8f9c999..14976dcd5 100644 --- a/src/Grid/Column/Resolver/ImageResolver.php +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -18,8 +18,9 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\ColumnDataTrait; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; -use Pimcore\Model\Asset; use Pimcore\Model\Element\ElementInterface; /** @@ -27,10 +28,13 @@ */ final class ImageResolver implements ColumnResolverInterface { - public function resolve(Column $columnDefinition, ElementInterface $element): string + use ColumnDataTrait; + public function resolve(Column $column, ElementInterface $element): ColumnData { - /** @var Asset $element */ - return $element->getRealFullPath(); + return $this->getColumnData( + $column, + $element->getRealFullPath() + ); } public function getType(): string diff --git a/src/Grid/Column/Resolver/IntegerResolver.php b/src/Grid/Column/Resolver/IntegerResolver.php index 1d72c0cb1..81dc85683 100644 --- a/src/Grid/Column/Resolver/IntegerResolver.php +++ b/src/Grid/Column/Resolver/IntegerResolver.php @@ -18,6 +18,8 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\ColumnDataTrait; use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\SimpleGetterTrait; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Element\ElementInterface; @@ -28,10 +30,14 @@ final class IntegerResolver implements ColumnResolverInterface { use SimpleGetterTrait; + use ColumnDataTrait; - public function resolve(Column $columnDefinition, ElementInterface $element): int + public function resolve(Column $column, ElementInterface $element): ColumnData { - return $this->getValue($columnDefinition, $element); + return $this->getColumnData( + $column, + $this->getValue($column, $element) + ); } public function getType(): string diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php index 29edf0014..796015f62 100644 --- a/src/Grid/Column/Resolver/StringResolver.php +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -18,6 +18,8 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\ColumnDataTrait; use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\SimpleGetterTrait; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Model\Element\ElementInterface; @@ -28,10 +30,14 @@ final class StringResolver implements ColumnResolverInterface { use SimpleGetterTrait; + use ColumnDataTrait; - public function resolve(Column $columnDefinition, ElementInterface $element): ?string + public function resolve(Column $column, ElementInterface $element): ColumnData { - return $this->getValue($columnDefinition, $element); + return $this->getColumnData( + $column, + $this->getValue($column, $element) + ); } public function getType(): string diff --git a/src/Grid/MappedParameter/GridParameter.php b/src/Grid/MappedParameter/GridParameter.php index 985af847f..e66e8bcd9 100644 --- a/src/Grid/MappedParameter/GridParameter.php +++ b/src/Grid/MappedParameter/GridParameter.php @@ -24,18 +24,18 @@ final readonly class GridParameter { public function __construct( - private int $id, + private int $folderId, private array $gridConfig, ) { } - public function getId(): int + public function getFolderId(): int { - return $this->id; + return $this->folderId; } - public function getGridConfig(): Configuration + public function getGridConfig(): array { - return new Configuration($this->gridConfig); + return $this->gridConfig; } } diff --git a/src/Grid/Schema/Column.php b/src/Grid/Schema/Column.php index b025617a5..24566b956 100644 --- a/src/Grid/Schema/Column.php +++ b/src/Grid/Schema/Column.php @@ -27,6 +27,7 @@ */ #[Schema( title: 'GridColumnDefinition', + required: ['key', 'group', 'sortable', 'editable', 'localizable', 'locale', 'type', 'config'], type: 'object' )] final readonly class Column @@ -42,12 +43,13 @@ public function __construct( private bool $editable, #[Property(description: 'Localizable', type: 'boolean', example: false)] private bool $localizable, + #[Property(description: 'Locale', type: 'string', example: 'en')] + private ?string $locale, #[Property(description: 'Type', type: 'string', example: 'integer')] private string $type, #[Property(description: 'Config', type: 'array', items: new Items(type: 'string'), example: ['key' => 'value'])] private array $config, ) { - } public function getConfig(): array @@ -80,6 +82,11 @@ public function isLocalizable(): bool return $this->localizable; } + public function getLocale(): ?string + { + return $this->locale; + } + public function getType(): string { return $this->type; diff --git a/src/Grid/Schema/ColumnData.php b/src/Grid/Schema/ColumnData.php index b6c66c084..0970e4688 100644 --- a/src/Grid/Schema/ColumnData.php +++ b/src/Grid/Schema/ColumnData.php @@ -33,7 +33,7 @@ public function __construct( private string $key, #[Property(description: 'Locale', type: 'string', example: 'en')] private ?string $locale, - #[Property(description: 'value', type: 'mixed', example: 73)] + #[Property(description: 'Value', type: 'mixed', example: 73)] private mixed $value ) { } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 92bf7db46..2909c1731 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -24,6 +24,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -56,12 +57,12 @@ public function __construct( $this->columnResolvers = $columnResolverLoader->loadColumnResolvers(); } - public function getAssetGrid(GridParameter $gridParameter): array + public function getAssetGrid(GridParameter $gridParameter): Collection { $result = $this->gridSearch->searchAssets($gridParameter); if(empty($result->getIds())) { - return []; + return new Collection(totalItems: 0, items: []); } $data = []; @@ -69,14 +70,18 @@ public function getAssetGrid(GridParameter $gridParameter): array foreach ($result->getItems() as $item) { $type = $item->getElementType()->value; $asset = $this->getElement($this->serviceResolver, $type, $item->getId()); + $data[] = $this->getGridDataForElement( - $this->getAssetGridConfiguration(), + $this->getConfigurationFromArray($gridParameter->getGridConfig()), $asset, $type ); } - return ['items' => $data]; + return new Collection( + totalItems: $result->getPagination()->getTotalItems(), + items: $data + ); } public function getGridDataForElement( @@ -89,11 +94,7 @@ public function getGridDataForElement( if (!$this->supports($column, $elementType)) { continue; } - $data['columns'][] = new ColumnData( - $column->getKey(), - null, - $this->columnResolvers[$column->getType()]->resolve($column, $element) - ); + $data['columns'][] = $this->columnResolvers[$column->getType()]->resolve($column, $element); } return $data; @@ -113,6 +114,7 @@ public function getAssetGridConfiguration(): Configuration sortable: $this->columnDefinitions[$type]->isSortable(), editable: false, localizable: false, + locale: null, type: $type, config: $this->columnDefinitions[$type]->getConfig() ); @@ -142,6 +144,7 @@ public function getConfigurationFromArray(array $config): Configuration sortable: $column['sortable'], editable: $column['editable'], localizable: $column['localizable'], + locale: $column['locale'], type: $column['type'], config: $column['config'] ); diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index d765596a4..69bc31fee 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -40,5 +41,5 @@ public function getGridDataForElement( public function getConfigurationFromArray(array $config): Configuration; - public function getAssetGrid(GridParameter $gridParameter): array; + public function getAssetGrid(GridParameter $gridParameter): Collection; } diff --git a/src/Grid/Util/Trait/ColumnDataTrait.php b/src/Grid/Util/Trait/ColumnDataTrait.php new file mode 100644 index 000000000..c8cbc00a0 --- /dev/null +++ b/src/Grid/Util/Trait/ColumnDataTrait.php @@ -0,0 +1,31 @@ +getKey(), $column->getLocale() , $value); + } +} \ No newline at end of file diff --git a/src/OpenApi/Attributes/Property/SingleInteger.php b/src/OpenApi/Attributes/Property/SingleInteger.php new file mode 100644 index 000000000..634314885 --- /dev/null +++ b/src/OpenApi/Attributes/Property/SingleInteger.php @@ -0,0 +1,34 @@ + Date: Tue, 2 Jul 2024 12:50:09 +0000 Subject: [PATCH 14/22] Apply php-cs-fixer changes --- src/Asset/Controller/Grid/GetController.php | 3 --- src/Grid/Attributes/Property/GridCollection.php | 2 +- src/Grid/Column/Resolver/FileSizeResolver.php | 1 + src/Grid/Column/Resolver/ImageResolver.php | 1 + src/Grid/MappedParameter/GridParameter.php | 2 -- src/Grid/Service/GridService.php | 1 - src/Grid/Util/Trait/ColumnDataTrait.php | 4 ++-- 7 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Asset/Controller/Grid/GetController.php b/src/Asset/Controller/Grid/GetController.php index 12f2a2888..b4e1d62f9 100644 --- a/src/Asset/Controller/Grid/GetController.php +++ b/src/Asset/Controller/Grid/GetController.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Grid; -use OpenApi\Attributes\JsonContent; use OpenApi\Attributes\Post; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; @@ -24,9 +23,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Property\GridCollection; use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Request\GridRequestBody; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; -use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Property\GenericCollection; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; diff --git a/src/Grid/Attributes/Property/GridCollection.php b/src/Grid/Attributes/Property/GridCollection.php index 70ca983b2..1238bf368 100644 --- a/src/Grid/Attributes/Property/GridCollection.php +++ b/src/Grid/Attributes/Property/GridCollection.php @@ -41,4 +41,4 @@ public function __construct() ) ); } -} \ No newline at end of file +} diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index 9a53d574f..a2587667f 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -30,6 +30,7 @@ final class FileSizeResolver implements ColumnResolverInterface { use ColumnDataTrait; + public function resolve(Column $column, ElementInterface $element): ColumnData { /** @var Asset $element */ diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php index 14976dcd5..cbfc17da3 100644 --- a/src/Grid/Column/Resolver/ImageResolver.php +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -29,6 +29,7 @@ final class ImageResolver implements ColumnResolverInterface { use ColumnDataTrait; + public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( diff --git a/src/Grid/MappedParameter/GridParameter.php b/src/Grid/MappedParameter/GridParameter.php index e66e8bcd9..bddc0dbb2 100644 --- a/src/Grid/MappedParameter/GridParameter.php +++ b/src/Grid/MappedParameter/GridParameter.php @@ -16,8 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; - /** * @internal */ diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 2909c1731..2c5ab2688 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -22,7 +22,6 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; diff --git a/src/Grid/Util/Trait/ColumnDataTrait.php b/src/Grid/Util/Trait/ColumnDataTrait.php index c8cbc00a0..f6601a3b4 100644 --- a/src/Grid/Util/Trait/ColumnDataTrait.php +++ b/src/Grid/Util/Trait/ColumnDataTrait.php @@ -26,6 +26,6 @@ trait ColumnDataTrait { private function getColumnData(Column $column, mixed $value): ColumnData { - return new ColumnData($column->getKey(), $column->getLocale() , $value); + return new ColumnData($column->getKey(), $column->getLocale(), $value); } -} \ No newline at end of file +} From adb179d0094d235f6cea6952677a7b4e07875761 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 14:53:30 +0200 Subject: [PATCH 15/22] Consistency check --- src/DataIndex/Grid/GridSearch.php | 3 ++- src/Grid/Service/GridService.php | 2 +- src/Grid/Util/Trait/SimpleGetterTrait.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index e19441e29..707a4b709 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -11,7 +11,7 @@ * LICENSE.md which is distributed with this source code. * * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) - * @license http://www.pimcore.org/license GPLv3 and PCL + * @license http://www.pimcore.org/license GPLv3 and PCL */ namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid; @@ -37,6 +37,7 @@ public function __construct( public function searchAssets(GridParameter $gridParameter): AssetSearchResult { + // TODO Try to repurpose filter concept from data-index $search = new AssetSearch(); /** @var User $user */ $user = $this->securityService->getCurrentUser(); diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 2c5ab2688..dc9b3ec05 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -60,7 +60,7 @@ public function getAssetGrid(GridParameter $gridParameter): Collection { $result = $this->gridSearch->searchAssets($gridParameter); - if(empty($result->getIds())) { + if (empty($result->getIds())) { return new Collection(totalItems: 0, items: []); } diff --git a/src/Grid/Util/Trait/SimpleGetterTrait.php b/src/Grid/Util/Trait/SimpleGetterTrait.php index a849b827f..381246cd5 100644 --- a/src/Grid/Util/Trait/SimpleGetterTrait.php +++ b/src/Grid/Util/Trait/SimpleGetterTrait.php @@ -30,8 +30,8 @@ trait SimpleGetterTrait */ private function getValue(Column $columnDefinition, ElementInterface $element): mixed { - $getter = 'get' . ucfirst($columnDefinition->getKey()); - if(method_exists($element, $getter) === false) { + $getter = $this->getGetter($columnDefinition); + if (method_exists($element, $getter) === false) { throw new InvalidArgumentException( 'Method ' . $getter . ' does not exist on ' . get_class($element) ); From 574f03e9fc991eeae64335288806fe64da5f7cfa Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 12:54:23 +0000 Subject: [PATCH 16/22] Apply php-cs-fixer changes --- src/DataIndex/Grid/GridSearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index 707a4b709..f6fcc6fef 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -11,7 +11,7 @@ * LICENSE.md which is distributed with this source code. * * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) - * @license http://www.pimcore.org/license GPLv3 and PCL + * @license http://www.pimcore.org/license GPLv3 and PCL */ namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid; From 0821a9a33289fcd0682e46a7e86a578a56234cce Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 15:00:18 +0200 Subject: [PATCH 17/22] Add exceptions to the party --- src/Asset/Controller/Grid/GetController.php | 5 ++--- src/Grid/Column/Resolver/DatetimeResolver.php | 4 ++++ src/Grid/Column/Resolver/FileSizeResolver.php | 4 ++++ src/Grid/Column/Resolver/ImageResolver.php | 4 ++++ src/Grid/Column/Resolver/IntegerResolver.php | 4 ++++ src/Grid/Column/Resolver/StringResolver.php | 4 ++++ src/Grid/Service/GridService.php | 7 +++++++ src/Grid/Service/GridServiceInterface.php | 4 ++++ 8 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Asset/Controller/Grid/GetController.php b/src/Asset/Controller/Grid/GetController.php index b4e1d62f9..bb9082dcb 100644 --- a/src/Asset/Controller/Grid/GetController.php +++ b/src/Asset/Controller/Grid/GetController.php @@ -18,8 +18,7 @@ use OpenApi\Attributes\Post; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Property\GridCollection; use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Request\GridRequestBody; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; @@ -49,7 +48,7 @@ public function __construct( } /** - * @throws NotFoundException|SearchException + * @throws InvalidArgumentException */ #[Route('/assets/grid', name: 'pimcore_studio_api_get_asset_grid', methods: ['POST'])] #[IsGranted(UserPermissions::ASSETS->value)] diff --git a/src/Grid/Column/Resolver/DatetimeResolver.php b/src/Grid/Column/Resolver/DatetimeResolver.php index 8ccb37035..63015cad7 100644 --- a/src/Grid/Column/Resolver/DatetimeResolver.php +++ b/src/Grid/Column/Resolver/DatetimeResolver.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; use Carbon\Carbon; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -33,6 +34,9 @@ final class DatetimeResolver implements ColumnResolverInterface use SimpleGetterTrait; use ColumnDataTrait; + /** + * @throws InvalidArgumentException + */ public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index a2587667f..754edcd7e 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -31,6 +32,9 @@ final class FileSizeResolver implements ColumnResolverInterface { use ColumnDataTrait; + /** + * @throws InvalidArgumentException + */ public function resolve(Column $column, ElementInterface $element): ColumnData { /** @var Asset $element */ diff --git a/src/Grid/Column/Resolver/ImageResolver.php b/src/Grid/Column/Resolver/ImageResolver.php index cbfc17da3..728b9d340 100644 --- a/src/Grid/Column/Resolver/ImageResolver.php +++ b/src/Grid/Column/Resolver/ImageResolver.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -30,6 +31,9 @@ final class ImageResolver implements ColumnResolverInterface { use ColumnDataTrait; + /** + * @throws InvalidArgumentException + */ public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( diff --git a/src/Grid/Column/Resolver/IntegerResolver.php b/src/Grid/Column/Resolver/IntegerResolver.php index 81dc85683..44c3a4e93 100644 --- a/src/Grid/Column/Resolver/IntegerResolver.php +++ b/src/Grid/Column/Resolver/IntegerResolver.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -32,6 +33,9 @@ final class IntegerResolver implements ColumnResolverInterface use SimpleGetterTrait; use ColumnDataTrait; + /** + * @throws InvalidArgumentException + */ public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( diff --git a/src/Grid/Column/Resolver/StringResolver.php b/src/Grid/Column/Resolver/StringResolver.php index 796015f62..04823c143 100644 --- a/src/Grid/Column/Resolver/StringResolver.php +++ b/src/Grid/Column/Resolver/StringResolver.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -32,6 +33,9 @@ final class StringResolver implements ColumnResolverInterface use SimpleGetterTrait; use ColumnDataTrait; + /** + * @throws InvalidArgumentException + */ public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index dc9b3ec05..4e136a83b 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; use Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; @@ -56,6 +57,9 @@ public function __construct( $this->columnResolvers = $columnResolverLoader->loadColumnResolvers(); } + /** + * @throws InvalidArgumentException + */ public function getAssetGrid(GridParameter $gridParameter): Collection { $result = $this->gridSearch->searchAssets($gridParameter); @@ -83,6 +87,9 @@ public function getAssetGrid(GridParameter $gridParameter): Collection ); } + /** + * @throws InvalidArgumentException + */ public function getGridDataForElement( Configuration $configuration, ElementInterface $element, diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 69bc31fee..3b1a091d0 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; @@ -33,6 +34,9 @@ public function getDocumentGridColumns(): Configuration; public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration; + /** + * @throws InvalidArgumentException + */ public function getGridDataForElement( Configuration $configuration, ElementInterface $element, From d19ab2489af3fc333c86eeb50e8913f1db33954e Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 15:33:55 +0200 Subject: [PATCH 18/22] Add events --- src/Grid/Event/GridColumnDataEvent.php | 39 ++++++++++++++++++++ src/Grid/Event/GridColumnDefinitionEvent.php | 39 ++++++++++++++++++++ src/Grid/Schema/Column.php | 22 ++++++----- src/Grid/Schema/ColumnData.php | 12 ++++-- src/Grid/Service/GridService.php | 25 +++++++++++-- 5 files changed, 121 insertions(+), 16 deletions(-) create mode 100644 src/Grid/Event/GridColumnDataEvent.php create mode 100644 src/Grid/Event/GridColumnDefinitionEvent.php diff --git a/src/Grid/Event/GridColumnDataEvent.php b/src/Grid/Event/GridColumnDataEvent.php new file mode 100644 index 000000000..161e82a44 --- /dev/null +++ b/src/Grid/Event/GridColumnDataEvent.php @@ -0,0 +1,39 @@ +columnData; + } +} diff --git a/src/Grid/Event/GridColumnDefinitionEvent.php b/src/Grid/Event/GridColumnDefinitionEvent.php new file mode 100644 index 000000000..6aec32bd9 --- /dev/null +++ b/src/Grid/Event/GridColumnDefinitionEvent.php @@ -0,0 +1,39 @@ +column; + } +} diff --git a/src/Grid/Schema/Column.php b/src/Grid/Schema/Column.php index 24566b956..c2432b38a 100644 --- a/src/Grid/Schema/Column.php +++ b/src/Grid/Schema/Column.php @@ -19,6 +19,8 @@ use OpenApi\Attributes\Items; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; +use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; +use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait; /** * Column contains all data + values that is needed for the grid @@ -30,25 +32,27 @@ required: ['key', 'group', 'sortable', 'editable', 'localizable', 'locale', 'type', 'config'], type: 'object' )] -final readonly class Column +final class Column implements AdditionalAttributesInterface { + use AdditionalAttributesTrait; + public function __construct( #[Property(description: 'Key', type: 'string', example: 'id')] - private string $key, + private readonly string $key, #[Property(description: 'Group', type: 'string', example: 'system')] - private string $group, + private readonly string $group, #[Property(description: 'Sortable', type: 'boolean', example: true)] - private bool $sortable, + private readonly bool $sortable, #[Property(description: 'Editable', type: 'boolean', example: false)] - private bool $editable, + private readonly bool $editable, #[Property(description: 'Localizable', type: 'boolean', example: false)] - private bool $localizable, + private readonly bool $localizable, #[Property(description: 'Locale', type: 'string', example: 'en')] - private ?string $locale, + private readonly ?string $locale, #[Property(description: 'Type', type: 'string', example: 'integer')] - private string $type, + private readonly string $type, #[Property(description: 'Config', type: 'array', items: new Items(type: 'string'), example: ['key' => 'value'])] - private array $config, + private readonly array $config, ) { } diff --git a/src/Grid/Schema/ColumnData.php b/src/Grid/Schema/ColumnData.php index 0970e4688..fdbddb36f 100644 --- a/src/Grid/Schema/ColumnData.php +++ b/src/Grid/Schema/ColumnData.php @@ -18,6 +18,8 @@ use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; +use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; +use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait; /** * @internal @@ -26,15 +28,17 @@ title: 'GridColumnData', type: 'object' )] -final readonly class ColumnData +final class ColumnData implements AdditionalAttributesInterface { + use AdditionalAttributesTrait; + public function __construct( #[Property(description: 'Key', type: 'string', example: 'id')] - private string $key, + private readonly string $key, #[Property(description: 'Locale', type: 'string', example: 'en')] - private ?string $locale, + private readonly ?string $locale, #[Property(description: 'Value', type: 'mixed', example: 73)] - private mixed $value + private readonly mixed $value ) { } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 4e136a83b..8ca6b22a4 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -21,6 +21,8 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Event\GridColumnDataEvent; +use Pimcore\Bundle\StudioBackendBundle\Grid\Event\GridColumnDefinitionEvent; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; @@ -28,6 +30,7 @@ use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * @internal @@ -51,7 +54,8 @@ public function __construct( ColumnResolverLoaderInterface $columnResolverLoader, private SystemColumnServiceInterface $systemColumnService, private GridSearchInterface $gridSearch, - private ServiceResolverInterface $serviceResolver + private ServiceResolverInterface $serviceResolver, + private EventDispatcherInterface $eventDispatcher ) { $this->columnDefinitions = $columnAdapterLoader->loadColumnDefinitions(); $this->columnResolvers = $columnResolverLoader->loadColumnResolvers(); @@ -100,7 +104,15 @@ public function getGridDataForElement( if (!$this->supports($column, $elementType)) { continue; } - $data['columns'][] = $this->columnResolvers[$column->getType()]->resolve($column, $element); + + $columnData = $this->columnResolvers[$column->getType()]->resolve($column, $element); + + $this->eventDispatcher->dispatch( + new GridColumnDataEvent($columnData), + GridColumnDataEvent::EVENT_NAME + ); + + $data['columns'][] = $columnData; } return $data; @@ -114,7 +126,7 @@ public function getAssetGridConfiguration(): Configuration if (!array_key_exists($type, $this->columnDefinitions)) { continue; } - $columns[] = new Column( + $column = new Column( key: $columnKey, group: 'system', sortable: $this->columnDefinitions[$type]->isSortable(), @@ -124,6 +136,13 @@ public function getAssetGridConfiguration(): Configuration type: $type, config: $this->columnDefinitions[$type]->getConfig() ); + + $this->eventDispatcher->dispatch( + new GridColumnDefinitionEvent($column), + GridColumnDefinitionEvent::EVENT_NAME + ); + + $columns[] = $column; } return new Configuration($columns); From 63260a9669e1b89c53f1a1a4ccbcdf2f9fef3589 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 15:46:17 +0200 Subject: [PATCH 19/22] Make trait and interface public --- src/Grid/Column/ColumnDefinitionInterface.php | 3 --- src/Grid/Util/Trait/SimpleGetterTrait.php | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/Grid/Column/ColumnDefinitionInterface.php b/src/Grid/Column/ColumnDefinitionInterface.php index c82cf7adb..b0df84413 100644 --- a/src/Grid/Column/ColumnDefinitionInterface.php +++ b/src/Grid/Column/ColumnDefinitionInterface.php @@ -16,9 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column; -/** - * @internal - */ interface ColumnDefinitionInterface { public function getType(): string; diff --git a/src/Grid/Util/Trait/SimpleGetterTrait.php b/src/Grid/Util/Trait/SimpleGetterTrait.php index 381246cd5..2bb25cb7e 100644 --- a/src/Grid/Util/Trait/SimpleGetterTrait.php +++ b/src/Grid/Util/Trait/SimpleGetterTrait.php @@ -20,9 +20,6 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Model\Element\ElementInterface; -/** - * @internal - */ trait SimpleGetterTrait { /** From 12e8d41d7d321f043546bcc8789dd9e9973ff0b5 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 15:49:53 +0200 Subject: [PATCH 20/22] Remove doctags --- src/Grid/Column/Resolver/FileSizeResolver.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Grid/Column/Resolver/FileSizeResolver.php b/src/Grid/Column/Resolver/FileSizeResolver.php index 754edcd7e..a2587667f 100644 --- a/src/Grid/Column/Resolver/FileSizeResolver.php +++ b/src/Grid/Column/Resolver/FileSizeResolver.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; @@ -32,9 +31,6 @@ final class FileSizeResolver implements ColumnResolverInterface { use ColumnDataTrait; - /** - * @throws InvalidArgumentException - */ public function resolve(Column $column, ElementInterface $element): ColumnData { /** @var Asset $element */ From dacc85cb146c6df85e5b18bc1458a0a9ae4528b5 Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 15:53:17 +0200 Subject: [PATCH 21/22] Remove Carbon for now --- src/Grid/Column/Resolver/DatetimeResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Column/Resolver/DatetimeResolver.php b/src/Grid/Column/Resolver/DatetimeResolver.php index 63015cad7..11ba97651 100644 --- a/src/Grid/Column/Resolver/DatetimeResolver.php +++ b/src/Grid/Column/Resolver/DatetimeResolver.php @@ -41,7 +41,7 @@ public function resolve(Column $column, ElementInterface $element): ColumnData { return $this->getColumnData( $column, - Carbon::create($this->getValue($column, $element))->toISOString() + $this->getValue($column, $element) ); } From 819f01a0fb35327a313783cf4184c4b0dc0b66df Mon Sep 17 00:00:00 2001 From: mattamon Date: Tue, 2 Jul 2024 13:53:42 +0000 Subject: [PATCH 22/22] Apply php-cs-fixer changes --- src/Grid/Column/Resolver/DatetimeResolver.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Grid/Column/Resolver/DatetimeResolver.php b/src/Grid/Column/Resolver/DatetimeResolver.php index 11ba97651..64f7a2012 100644 --- a/src/Grid/Column/Resolver/DatetimeResolver.php +++ b/src/Grid/Column/Resolver/DatetimeResolver.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver; -use Carbon\Carbon; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;