diff --git a/README.md b/README.md index 32835a5f5..c17e4b069 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,5 @@ Swagger-ui is available at `/studio/api/docs` and the OpenApi Specification is a ## Documentation Overview - [Installation](./doc/01_Installation.md) + +- [Grid](./doc/03_Grid.md) diff --git a/doc/03_Grid.md b/doc/03_Grid.md new file mode 100644 index 000000000..f88b4ad8f --- /dev/null +++ b/doc/03_Grid.md @@ -0,0 +1,13 @@ +# Grid + +On the request level we have three main components for the grid: `Column`, `ColumnConfiguration` and `ColumnData`. + +## Column +A column is a single column in the grid. It has a name, type and a locale. It is used to get the data for the column. +in addition, it has a configuration which can be used to configure the column, like the direction of the sorting + +## ColumnConfiguration +A column configuration represents how the column should behave, for example if it should be sort-able or editable. + +## ColumnData +A column data is the actual data for a column. It has a reference to the column and the actual data. diff --git a/src/Asset/Attributes/Request/CsvExportRequestBody.php b/src/Asset/Attributes/Request/CsvExportRequestBody.php index a6b77ef1f..6679a43ed 100644 --- a/src/Asset/Attributes/Request/CsvExportRequestBody.php +++ b/src/Asset/Attributes/Request/CsvExportRequestBody.php @@ -22,7 +22,7 @@ use OpenApi\Attributes\Property; use OpenApi\Attributes\RequestBody; use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constants\Csv; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; /** * @internal @@ -36,7 +36,11 @@ public function __construct() content: new JsonContent( properties: [ new Property(property: 'assets', type: 'array', items: new Items(type: 'integer'), example: [83]), - new Property(property: 'gridConfig', ref: Configuration::class), + new Property( + property: 'gridConfig', + type: 'array', + items: new Items(ref: Column::class) + ), new Property(property: 'settings', properties: [ new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'), new Property( diff --git a/src/Asset/Controller/Grid/Configuration/GetController.php b/src/Asset/Controller/Grid/Configuration/GetController.php index b0bf82665..ee42be1cc 100644 --- a/src/Asset/Controller/Grid/Configuration/GetController.php +++ b/src/Asset/Controller/Grid/Configuration/GetController.php @@ -17,11 +17,13 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Grid\Configuration; use OpenApi\Attributes\Get; +use OpenApi\Attributes\Items; use OpenApi\Attributes\JsonContent; +use OpenApi\Attributes\Property; 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\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; @@ -60,7 +62,12 @@ public function __construct( #[SuccessResponse( description: 'Grid configuration', content: new JsonContent( - ref: Configuration::class + properties: [ + new Property( + property: 'columns', + type: 'array', + items: new Items(ref: ColumnConfiguration::class), + )], ) )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Grid/GetController.php b/src/Asset/Controller/Grid/GetController.php index bb9082dcb..e3049de1f 100644 --- a/src/Asset/Controller/Grid/GetController.php +++ b/src/Asset/Controller/Grid/GetController.php @@ -69,6 +69,7 @@ public function __construct( #[DefaultResponses([ HttpResponseCodes::UNAUTHORIZED, HttpResponseCodes::NOT_FOUND, + HttpResponseCodes::BAD_REQUEST, ])] public function getAssetGrid(#[MapRequestPayload] GridParameter $gridParameter): JsonResponse { diff --git a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php index 25a22f85d..a0bb203f5 100644 --- a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php +++ b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php @@ -98,11 +98,11 @@ public function __invoke(CsvCreationMessage $message): void } $settings = $this->extractConfigFieldFromJobStepConfig($message, 'settings'); - $configuration = $this->gridService->getConfigurationFromArray( + $columnCollection = $this->gridService->getConfigurationFromArray( $this->extractConfigFieldFromJobStepConfig($message, 'configuration') ); - $csv = $this->csvService->getCsvFile($jobRun->getId(), $configuration, $settings); + $csv = $this->csvService->getCsvFile($jobRun->getId(), $columnCollection, $settings); if (!$csv) { $this->abort($this->getAbortData( @@ -125,7 +125,7 @@ public function __invoke(CsvCreationMessage $message): void } $assetData = $this->gridService->getGridValuesForElement( - $configuration, + $columnCollection, $asset, ElementTypes::TYPE_ASSET ); diff --git a/src/Asset/Service/ExecutionEngine/CsvService.php b/src/Asset/Service/ExecutionEngine/CsvService.php index 1bd8f4dbd..8f601c67b 100644 --- a/src/Asset/Service/ExecutionEngine/CsvService.php +++ b/src/Asset/Service/ExecutionEngine/CsvService.php @@ -29,8 +29,8 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\EnvironmentException; use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config; use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Jobs; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\StorageDirectories; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\TempFilePathTrait; @@ -80,14 +80,14 @@ public function generateCsvFile(ExportAssetParameter $exportAssetParameter): str return $this->getTempFilePath($jobRun->getId(), self::CSV_FILE_PATH); } - public function getCsvFile(int $id, Configuration $configuration, array $settings): string + public function getCsvFile(int $id, ColumnCollection $columnCollection, array $settings): string { $storage = $this->storageResolver->get(StorageDirectories::TEMP->value); $file = $this->getTempFileName($id, self::CSV_FILE_NAME); try { if (!$storage->fileExists($file)) { - $headers = $this->getHeaders($configuration, $settings); + $headers = $this->getHeaders($columnCollection, $settings); $storage->write( $file, implode($settings[Csv::SETTINGS_DELIMITER->value] ?? ',', $headers). Csv::NEW_LINE->value @@ -125,7 +125,7 @@ private function encodeFunc(?string $value): string return '"' . $value . '"'; } - private function getHeaders(Configuration $configuration, array $settings): array + private function getHeaders(ColumnCollection $columnCollection, array $settings): array { $header = $settings[Csv::SETTINGS_HEADER->value] ?? Csv::SETTINGS_HEADER_NO_HEADER->value; if ($header === Csv::SETTINGS_HEADER_NO_HEADER->value) { @@ -133,7 +133,7 @@ private function getHeaders(Configuration $configuration, array $settings): arra } return $this->gridService->getColumnKeys( - $configuration, + $columnCollection, $header === Csv::SETTINGS_HEADER_NAME->value ); } diff --git a/src/Asset/Service/ExecutionEngine/CsvServiceInterface.php b/src/Asset/Service/ExecutionEngine/CsvServiceInterface.php index 3dd4de723..f7bc3af96 100644 --- a/src/Asset/Service/ExecutionEngine/CsvServiceInterface.php +++ b/src/Asset/Service/ExecutionEngine/CsvServiceInterface.php @@ -17,7 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine; use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportAssetParameter; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection; /** * @internal @@ -28,7 +28,7 @@ interface CsvServiceInterface public const CSV_FILE_PATH = PIMCORE_SYSTEM_TEMP_DIRECTORY . '/' . self::CSV_FILE_NAME; - public function getCsvFile(int $id, Configuration $configuration, array $settings): string; + public function getCsvFile(int $id, ColumnCollection $columnCollection, array $settings): string; public function addData(string $filePath, string $delimiter, array $data): void; diff --git a/src/Grid/Attributes/Request/GridRequestBody.php b/src/Grid/Attributes/Request/GridRequestBody.php index cc0e8c873..992de7ee7 100644 --- a/src/Grid/Attributes/Request/GridRequestBody.php +++ b/src/Grid/Attributes/Request/GridRequestBody.php @@ -35,19 +35,13 @@ public function __construct() parent::__construct( required: true, content: new JsonContent( - required: ['folderId', 'gridConfig'], + required: ['folderId', 'columns'], properties: [ new SingleInteger(propertyName: 'folderId'), new Property( - property: 'gridConfig', - properties: [ - new Property( - property: 'columns', - type: 'array', - items: new Items(ref: Column::class) - ), - ], - type: 'object' + property: 'columns', + type: 'array', + items: new Items(ref: Column::class) ), ], type: 'object', diff --git a/src/Grid/Column/Collector/MetaDataCollector.php b/src/Grid/Column/Collector/MetaDataCollector.php index 437a8163a..38ecb7f6b 100644 --- a/src/Grid/Column/Collector/MetaDataCollector.php +++ b/src/Grid/Column/Collector/MetaDataCollector.php @@ -19,7 +19,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\FrontendType; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; use Pimcore\Bundle\StudioBackendBundle\MetaData\Repository\MetaDataRepositoryInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use function array_key_exists; @@ -42,9 +42,9 @@ public function getCollectorName(): string /** * @param ColumnDefinitionInterface[] $availableColumnDefinitions * - * @return Column[] + * @return ColumnConfiguration[] */ - public function getColumnDefinitions(array $availableColumnDefinitions): array + public function getColumnConfigurations(array $availableColumnDefinitions): array { return array_merge( $this->getDefaultMetaData(), @@ -54,14 +54,14 @@ public function getColumnDefinitions(array $availableColumnDefinitions): array /** * - * @return Column[] + * @return ColumnConfiguration[] */ private function getDefaultMetaData(): array { $defaultMetadata = ['title', 'alt', 'copyright']; $columns = []; foreach ($defaultMetadata as $metadata) { - $columns[] = new Column( + $columns[] = new ColumnConfiguration( key: $metadata, group: 'default_metadata', sortable: true, @@ -80,7 +80,7 @@ private function getDefaultMetaData(): array /** * @param ColumnDefinitionInterface[] $availableColumnDefinitions * - * @return Column[] + * @return ColumnConfiguration[] */ private function getPredefinedMetaData(array $availableColumnDefinitions): array { @@ -93,7 +93,7 @@ private function getPredefinedMetaData(array $availableColumnDefinitions): array continue; } - $columns[] = new Column( + $columns[] = new ColumnConfiguration( key: $item->getName(), group: 'predefined_metadata', sortable: $availableColumnDefinitions[$type]->isSortable(), diff --git a/src/Grid/Column/Collector/SystemFieldCollector.php b/src/Grid/Column/Collector/SystemFieldCollector.php index b92c59cac..c6086237c 100644 --- a/src/Grid/Column/Collector/SystemFieldCollector.php +++ b/src/Grid/Column/Collector/SystemFieldCollector.php @@ -18,7 +18,7 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; use Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use function array_key_exists; @@ -41,9 +41,9 @@ public function getCollectorName(): string /** * @param ColumnDefinitionInterface[] $availableColumnDefinitions * - * @return Column[] + * @return ColumnConfiguration[] */ - public function getColumnDefinitions(array $availableColumnDefinitions): array + public function getColumnConfigurations(array $availableColumnDefinitions): array { $systemColumns = $this->systemColumnService->getSystemColumnsForAssets(); $columns = []; @@ -53,7 +53,7 @@ public function getColumnDefinitions(array $availableColumnDefinitions): array continue; } - $column = new Column( + $column = new ColumnConfiguration( key: $columnKey, group: $this->getCollectorName(), sortable: $availableColumnDefinitions[$type]->isSortable(), diff --git a/src/Grid/Column/ColumnCollectorInterface.php b/src/Grid/Column/ColumnCollectorInterface.php index 4afcbc419..4f18d6ca4 100644 --- a/src/Grid/Column/ColumnCollectorInterface.php +++ b/src/Grid/Column/ColumnCollectorInterface.php @@ -16,7 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; interface ColumnCollectorInterface { @@ -25,9 +25,9 @@ public function getCollectorName(): string; /** * @param ColumnDefinitionInterface[] $availableColumnDefinitions * - * @return Column[] + * @return ColumnConfiguration[] */ - public function getColumnDefinitions(array $availableColumnDefinitions): array; + public function getColumnConfigurations(array $availableColumnDefinitions): array; public function supportedElementTypes(): array; } diff --git a/src/Grid/Event/GridColumnDefinitionEvent.php b/src/Grid/Event/GridColumnConfigurationEvent.php similarity index 70% rename from src/Grid/Event/GridColumnDefinitionEvent.php rename to src/Grid/Event/GridColumnConfigurationEvent.php index 6aec32bd9..7a0bf4330 100644 --- a/src/Grid/Event/GridColumnDefinitionEvent.php +++ b/src/Grid/Event/GridColumnConfigurationEvent.php @@ -17,14 +17,14 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Event; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; -final class GridColumnDefinitionEvent extends AbstractPreResponseEvent +final class GridColumnConfigurationEvent extends AbstractPreResponseEvent { - public const EVENT_NAME = 'pre_response.grid_column_definition'; + public const EVENT_NAME = 'pre_response.grid_column_configuration'; public function __construct( - private readonly Column $column + private readonly ColumnConfiguration $column ) { parent::__construct($column); } @@ -32,7 +32,7 @@ public function __construct( /** * Use this to get additional infos out of the response object */ - public function getConfiguration(): Column + public function getConfiguration(): ColumnConfiguration { return $this->column; } diff --git a/src/Grid/MappedParameter/GridParameter.php b/src/Grid/MappedParameter/GridParameter.php index bddc0dbb2..27490116c 100644 --- a/src/Grid/MappedParameter/GridParameter.php +++ b/src/Grid/MappedParameter/GridParameter.php @@ -23,7 +23,7 @@ { public function __construct( private int $folderId, - private array $gridConfig, + private array $columns, ) { } @@ -32,8 +32,8 @@ public function getFolderId(): int return $this->folderId; } - public function getGridConfig(): array + public function getColumns(): array { - return $this->gridConfig; + return $this->columns; } } diff --git a/src/Grid/Schema/Column.php b/src/Grid/Schema/Column.php index 6e5e41e44..b5d6f9cdf 100644 --- a/src/Grid/Schema/Column.php +++ b/src/Grid/Schema/Column.php @@ -19,75 +19,38 @@ 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 + * Contains all data that is needed to get all the data for the column. * * @internal */ #[Schema( - title: 'GridColumnDefinition', - required: ['key', 'group', 'sortable', 'editable', 'localizable', 'locale', 'type', 'config'], + title: 'Grid Column Request', + required: ['key', 'type', 'config'], type: 'object' )] -final class Column implements AdditionalAttributesInterface +final readonly class Column { - use AdditionalAttributesTrait; - public function __construct( #[Property(description: 'Key', type: 'string', example: 'id')] - private readonly string $key, - #[Property(description: 'Group', type: 'string', example: 'system')] - private readonly string $group, - #[Property(description: 'Sortable', type: 'boolean', example: true)] - private readonly bool $sortable, - #[Property(description: 'Editable', type: 'boolean', example: false)] - private readonly bool $editable, - #[Property(description: 'Localizable', type: 'boolean', example: false)] - private readonly bool $localizable, + private string $key, #[Property(description: 'Locale', type: 'string', example: 'en')] - private readonly ?string $locale, - #[Property(description: 'Type', type: 'string', example: 'integer')] - private readonly string $type, - #[Property(description: 'Frontend Type', type: 'string', example: 'integer')] - private readonly string $frontendType, + private ?string $locale, + #[Property(description: 'Type', type: 'string', example: 'system.integer')] + private string $type, + #[Property(description: 'Group', type: 'string', example: 'system')] + private ?string $group, #[Property(description: 'Config', type: 'array', items: new Items(type: 'string'), example: ['key' => 'value'])] - private readonly array $config, + 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 getLocale(): ?string { return $this->locale; @@ -98,8 +61,13 @@ public function getType(): string return $this->type; } - public function getFrontendType(): string + public function getGroup(): string { - return $this->frontendType; + return $this->group; + } + + public function getConfig(): array + { + return $this->config; } } diff --git a/src/Grid/Schema/ColumnConfiguration.php b/src/Grid/Schema/ColumnConfiguration.php new file mode 100644 index 000000000..6c3242126 --- /dev/null +++ b/src/Grid/Schema/ColumnConfiguration.php @@ -0,0 +1,105 @@ + 'value'])] + private readonly 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 getLocale(): ?string + { + return $this->locale; + } + + public function getType(): string + { + return $this->type; + } + + public function getFrontendType(): string + { + return $this->frontendType; + } +} diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 89d2e35dc..a4dc18646 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -16,18 +16,20 @@ namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; +use Exception; 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\ColumnCollectorInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\Grid\Event\GridColumnConfigurationEvent; 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\ColumnConfiguration; use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; -use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; @@ -87,7 +89,7 @@ public function getAssetGrid(GridParameter $gridParameter): Collection $asset = $this->getElement($this->serviceResolver, $type, $item->getId()); $data[] = $this->getGridDataForElement( - $this->getConfigurationFromArray($gridParameter->getGridConfig()), + $this->getConfigurationFromArray($gridParameter->getColumns()), $asset, $type ); @@ -103,12 +105,12 @@ public function getAssetGrid(GridParameter $gridParameter): Collection * @throws InvalidArgumentException */ public function getGridDataForElement( - Configuration $configuration, + ColumnCollection $columnCollection, ElementInterface $element, string $elementType ): array { $data = []; - foreach ($configuration->getColumns() as $column) { + foreach ($columnCollection->getColumns() as $column) { // move this to the resolver if (!$this->supports($column, $elementType)) { continue; @@ -128,11 +130,11 @@ public function getGridDataForElement( } public function getGridValuesForElement( - Configuration $configuration, + ColumnCollection $columnCollection, ElementInterface $element, string $elementType ): array { - $data = $this->getGridDataForElement($configuration, $element, $elementType); + $data = $this->getGridDataForElement($columnCollection, $element, $elementType); return array_map( static fn (ColumnData $columnData) => $columnData->getValue(), @@ -140,7 +142,10 @@ public function getGridValuesForElement( ); } - public function getAssetGridConfiguration(): Configuration + /** + * @return ColumnConfiguration[] + */ + public function getAssetGridConfiguration(): array { $columns = []; foreach ($this->getColumnCollectors() as $collector) { @@ -151,7 +156,7 @@ public function getAssetGridConfiguration(): Configuration $columns = array_merge( $columns, - $collector->getColumnDefinitions( + $collector->getColumnConfigurations( $this->getColumnDefinitions() ) ); @@ -159,52 +164,54 @@ public function getAssetGridConfiguration(): Configuration foreach ($columns as $column) { $this->eventDispatcher->dispatch( - new GridColumnDefinitionEvent($column), - GridColumnDefinitionEvent::EVENT_NAME + new GridColumnConfigurationEvent($column), + GridColumnConfigurationEvent::EVENT_NAME ); } - return new Configuration($columns); + return $columns; } - public function getDocumentGridColumns(): Configuration + public function getDocumentGridColumns(): ColumnCollection { - return new Configuration([]); + return new ColumnCollection([]); } - public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration + public function getDataObjectGridColumns(ClassDefinition $classDefinition): ColumnCollection { - return new Configuration([]); + return new ColumnCollection([]); } - public function getConfigurationFromArray(array $config): Configuration + /** + * @throws InvalidArgumentException + */ + public function getConfigurationFromArray(array $config): ColumnCollection { $columns = []; - - foreach ($config['columns'] as $column) { - $columns[] = new Column( - key: $column['key'], - group: $column['group'], - sortable: $column['sortable'], - editable: $column['editable'], - localizable: $column['localizable'], - locale: $column['locale'], - type: $column['type'], - frontendType: $column['frontendType'], - config: $column['config'] - ); + foreach ($config as $column) { + try { + $columns[] = new Column( + key: $column['key'], + locale: $column['locale'] ?? null, + type: $column['type'], + group: $column['group'] ?? null, + config: $column['config'] + ); + } catch (Exception $e) { + throw new InvalidArgumentException('Invalid column configuration'); + } } - return new Configuration($columns); + return new ColumnCollection($columns); } - public function getColumnKeys(Configuration $configuration, bool $withGroup = false): array + public function getColumnKeys(ColumnCollection $columnCollection, bool $withGroup = false): array { return array_map( static function (Column $column) use ($withGroup) { return $column->getKey() . ($withGroup ? '~' . $column->getGroup() : ''); }, - $configuration->getColumns() + $columnCollection->getColumns() ); } @@ -224,6 +231,9 @@ private function supports(Column $column, string $elementType): bool return true; } + /** + * @return array + */ private function getColumnDefinitions(): array { if ($this->columnDefinitions) { diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 22b64b170..29bdbb24c 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -18,7 +18,8 @@ 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\Grid\Schema\ColumnConfiguration; +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\Element\ElementInterface; @@ -28,30 +29,33 @@ */ interface GridServiceInterface { - public function getAssetGridConfiguration(): Configuration; + /** + * @return ColumnConfiguration[] + */ + public function getAssetGridConfiguration(): array; - public function getDocumentGridColumns(): Configuration; + public function getDocumentGridColumns(): ColumnCollection; - public function getDataObjectGridColumns(ClassDefinition $classDefinition): Configuration; + public function getDataObjectGridColumns(ClassDefinition $classDefinition): ColumnCollection; /** * @throws InvalidArgumentException */ public function getGridDataForElement( - Configuration $configuration, + ColumnCollection $columnCollection, ElementInterface $element, string $elementType ): array; public function getGridValuesForElement( - Configuration $configuration, + ColumnCollection $columnCollection, ElementInterface $element, string $elementType ): array; - public function getConfigurationFromArray(array $config): Configuration; + public function getConfigurationFromArray(array $config): ColumnCollection; public function getAssetGrid(GridParameter $gridParameter): Collection; - public function getColumnKeys(Configuration $configuration, bool $withGroup = false): array; + public function getColumnKeys(ColumnCollection $columnCollection, bool $withGroup = false): array; } diff --git a/src/Grid/Schema/Configuration.php b/src/Grid/Util/Collection/ColumnCollection.php similarity index 65% rename from src/Grid/Schema/Configuration.php rename to src/Grid/Util/Collection/ColumnCollection.php index 685884fad..61790142e 100644 --- a/src/Grid/Schema/Configuration.php +++ b/src/Grid/Util/Collection/ColumnCollection.php @@ -14,30 +14,19 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Grid\Schema; +namespace Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection; -use OpenApi\Attributes\Items; -use OpenApi\Attributes\Property; -use OpenApi\Attributes\Schema; +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; /** * @internal */ -#[Schema( - title: 'GridConfiguration', - type: 'object' -)] -final readonly class Configuration +final readonly class ColumnCollection { /** * @param array $columns */ public function __construct( - #[Property( - property: 'columns', - type: 'array', - items: new Items(ref: Column::class) - )] private array $columns, ) { }