diff --git a/doc/03_Grid.md b/doc/03_Grid.md index caa2b9a9a..fafdf9582 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -8,6 +8,7 @@ in addition, it has a configuration which can be used to configure the column, l ## ColumnConfiguration A column configuration represents how the column should behave, for example if it should be sort-able or editable. +For the column to be exportable please make sure that it can be represented as a string. ## 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/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php index 4e74632f6..e1a0c423c 100644 --- a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php +++ b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php @@ -57,8 +57,10 @@ public function __invoke(CsvCreationMessage $message): void } $settings = $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_SETTINGS->value); $columnCollection = $this->gridService->getConfigurationFromArray( - $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value) + $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value), + true ); + if (!isset($jobRun->getContext()[Csv::ASSET_EXPORT_DATA->value])) { $this->abort($this->getAbortData( Config::CSV_CREATION_FAILED_MESSAGE->value, diff --git a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php index e226d63e8..84c645461 100644 --- a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php +++ b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php @@ -85,8 +85,10 @@ public function __invoke(CsvCollectionMessage $message): void return; } + $columnCollection = $this->gridService->getConfigurationFromArray( - $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value) + $this->extractConfigFieldFromJobStepConfig($message, Csv::JOB_STEP_CONFIG_CONFIGURATION->value), + true ); try { diff --git a/src/Grid/Column/ColumnDefinitionInterface.php b/src/Grid/Column/ColumnDefinitionInterface.php index ba333fd94..7a0e21558 100644 --- a/src/Grid/Column/ColumnDefinitionInterface.php +++ b/src/Grid/Column/ColumnDefinitionInterface.php @@ -25,4 +25,6 @@ public function getConfig(mixed $config): array; public function isSortable(): bool; public function getFrontendType(): string; + + public function isExportable(): bool; } diff --git a/src/Grid/Column/Definition/MetaData/AssetDefinition.php b/src/Grid/Column/Definition/MetaData/AssetDefinition.php index 4e69cf4a2..4b33e102d 100644 --- a/src/Grid/Column/Definition/MetaData/AssetDefinition.php +++ b/src/Grid/Column/Definition/MetaData/AssetDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::ELEMENT_DROPZONE->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/CheckboxDefinition.php b/src/Grid/Column/Definition/MetaData/CheckboxDefinition.php index 6dd65b568..6deefe68c 100644 --- a/src/Grid/Column/Definition/MetaData/CheckboxDefinition.php +++ b/src/Grid/Column/Definition/MetaData/CheckboxDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::CHECKBOX->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/DataObjectDefinition.php b/src/Grid/Column/Definition/MetaData/DataObjectDefinition.php index c9b6d1418..541086db2 100644 --- a/src/Grid/Column/Definition/MetaData/DataObjectDefinition.php +++ b/src/Grid/Column/Definition/MetaData/DataObjectDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::ELEMENT_DROPZONE->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/DateDefinition.php b/src/Grid/Column/Definition/MetaData/DateDefinition.php index ad68c4893..8f3465a29 100644 --- a/src/Grid/Column/Definition/MetaData/DateDefinition.php +++ b/src/Grid/Column/Definition/MetaData/DateDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::DATETIME->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/DocumentDefinition.php b/src/Grid/Column/Definition/MetaData/DocumentDefinition.php index a9dc5681a..f816d3ce0 100644 --- a/src/Grid/Column/Definition/MetaData/DocumentDefinition.php +++ b/src/Grid/Column/Definition/MetaData/DocumentDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::ELEMENT_DROPZONE->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/InputDefinition.php b/src/Grid/Column/Definition/MetaData/InputDefinition.php index 005bfe8ce..495dc1809 100644 --- a/src/Grid/Column/Definition/MetaData/InputDefinition.php +++ b/src/Grid/Column/Definition/MetaData/InputDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::INPUT->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/SelectDefinition.php b/src/Grid/Column/Definition/MetaData/SelectDefinition.php index 362c25e14..ad6e35be3 100644 --- a/src/Grid/Column/Definition/MetaData/SelectDefinition.php +++ b/src/Grid/Column/Definition/MetaData/SelectDefinition.php @@ -46,4 +46,9 @@ public function getFrontendType(): string { return FrontendType::SELECT->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/MetaData/TextareaDefinition.php b/src/Grid/Column/Definition/MetaData/TextareaDefinition.php index 2ef244bd3..f079bb979 100644 --- a/src/Grid/Column/Definition/MetaData/TextareaDefinition.php +++ b/src/Grid/Column/Definition/MetaData/TextareaDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::TEXTAREA->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/System/DatetimeDefinition.php b/src/Grid/Column/Definition/System/DatetimeDefinition.php index 4cb4f6bcd..8e1443612 100644 --- a/src/Grid/Column/Definition/System/DatetimeDefinition.php +++ b/src/Grid/Column/Definition/System/DatetimeDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::DATETIME->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/System/FileSizeDefinition.php b/src/Grid/Column/Definition/System/FileSizeDefinition.php index 6f94aae45..9ce672f3b 100644 --- a/src/Grid/Column/Definition/System/FileSizeDefinition.php +++ b/src/Grid/Column/Definition/System/FileSizeDefinition.php @@ -43,4 +43,9 @@ public function getFrontendType(): string { return FrontendType::INPUT->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/System/ImageDefinition.php b/src/Grid/Column/Definition/System/ImageDefinition.php index 0ea07c79a..2d48d16ba 100644 --- a/src/Grid/Column/Definition/System/ImageDefinition.php +++ b/src/Grid/Column/Definition/System/ImageDefinition.php @@ -43,4 +43,9 @@ public function getFrontendType(): string { return FrontendType::IMAGE->value; } + + public function isExportable(): bool + { + return false; + } } diff --git a/src/Grid/Column/Definition/System/IntegerDefinition.php b/src/Grid/Column/Definition/System/IntegerDefinition.php index 038e67a3a..11a4e874a 100644 --- a/src/Grid/Column/Definition/System/IntegerDefinition.php +++ b/src/Grid/Column/Definition/System/IntegerDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::INPUT->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Column/Definition/System/StringDefinition.php b/src/Grid/Column/Definition/System/StringDefinition.php index d1047fca7..f0df6e0e6 100644 --- a/src/Grid/Column/Definition/System/StringDefinition.php +++ b/src/Grid/Column/Definition/System/StringDefinition.php @@ -44,4 +44,9 @@ public function getFrontendType(): string { return FrontendType::INPUT->value; } + + public function isExportable(): bool + { + return true; + } } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index 6dfa791da..8aeffc404 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -155,12 +155,8 @@ public function getAssetGridConfiguration(): array continue; } - $columns = array_merge( - $columns, - $collector->getColumnConfigurations( - $this->getColumnDefinitions() - ) - ); + // rather use the spread operator instead of array_merge in a loop + $columns = [...$columns, ...$collector->getColumnConfigurations($this->getColumnDefinitions())]; } foreach ($columns as $column) { @@ -186,10 +182,14 @@ public function getDataObjectGridColumns(ClassDefinition $classDefinition): Colu /** * @throws InvalidArgumentException */ - public function getConfigurationFromArray(array $config): ColumnCollection + public function getConfigurationFromArray(array $config, bool $isExport = false): ColumnCollection { $columns = []; foreach ($config as $column) { + if ($isExport && !$this->isExportable($column['type'])) { + throw new InvalidArgumentException('Column type is not exportable'); + } + try { $columns[] = new Column( key: $column['key'], @@ -198,7 +198,7 @@ public function getConfigurationFromArray(array $config): ColumnCollection group: $column['group'] ?? null, config: $column['config'] ); - } catch (Exception $e) { + } catch (Exception) { throw new InvalidArgumentException('Invalid column configuration'); } } @@ -268,4 +268,13 @@ private function getColumnResolvers(): array return $this->columnResolvers; } + + private function isExportable(string $type): bool + { + if (!array_key_exists($type, $this->getColumnDefinitions())) { + return false; + } + + return $this->getColumnDefinitions()[$type]->isExportable(); + } } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index 4b0e65e2e..f3c39a03e 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -56,7 +56,7 @@ public function getGridValuesForElement( string $elementType ): array; - public function getConfigurationFromArray(array $config): ColumnCollection; + public function getConfigurationFromArray(array $config, bool $isExport = false): ColumnCollection; public function getAssetGrid(GridParameter $gridParameter): Collection;