mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Regenerate data from saved export on formatter test
[ci-skip]
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Export;
|
||||
use Chill\MainBundle\Entity\SavedExport;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Chill\MainBundle\Form\Type\Export\FormatterType;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
@@ -33,11 +34,18 @@ final readonly class ExportFormHelper
|
||||
return match ($step) {
|
||||
'centers', 'generate_centers' => ['centers' => $this->authorizationHelper->getReachableCenters($export->requiredRole())],
|
||||
'export', 'generate_export' => ['export' => $this->getDefaultDataStepExport($export, $options)],
|
||||
'formatter', 'generate_formatter' => [],
|
||||
'formatter', 'generate_formatter' => ['formatter' => $this->getDefaultDataStepFormatter($options)],
|
||||
default => throw new \LogicException("step not allowed : " . $step),
|
||||
};
|
||||
}
|
||||
|
||||
private function getDefaultDataStepFormatter(array $options): array
|
||||
{
|
||||
$formatter = $this->exportManager->getFormatter($options['formatter_alias']);
|
||||
|
||||
return $formatter->getFormDefaultData($options['aggregator_aliases']);
|
||||
}
|
||||
|
||||
private function getDefaultDataStepExport(ExportInterface|DirectExportInterface $export, array $options): array
|
||||
{
|
||||
$data = [
|
||||
@@ -87,7 +95,7 @@ final readonly class ExportFormHelper
|
||||
return match ($step) {
|
||||
'centers', 'generate_centers' => $this->savedExportDataToFormDataStepCenter($savedExport),
|
||||
'export', 'generate_export' => $this->savedExportDataToFormDataStepExport($savedExport, $formOptions),
|
||||
'formatter', 'generate_formatter' => [],
|
||||
'formatter', 'generate_formatter' => $this->savedExportDataToFormDataStepFormatter($savedExport, $formOptions),
|
||||
default => throw new \LogicException("this step is not allowed: " . $step),
|
||||
};
|
||||
}
|
||||
@@ -134,4 +142,27 @@ final readonly class ExportFormHelper
|
||||
|
||||
return $form->getData();
|
||||
}
|
||||
|
||||
private function savedExportDataToFormDataStepFormatter(
|
||||
SavedExport $savedExport,
|
||||
array $formOptions
|
||||
): array {
|
||||
dump(__METHOD__);
|
||||
$builder = $this->formFactory
|
||||
->createBuilder(
|
||||
FormType::class,
|
||||
[],
|
||||
[
|
||||
'csrf_protection' => false,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('formatter', FormatterType::class, [
|
||||
'export_alias' => $savedExport->getExportAlias(), ...$formOptions
|
||||
]);
|
||||
$form = $builder->getForm();
|
||||
$form->submit($savedExport->getOptions()['formatter']);
|
||||
|
||||
return $form->getData();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user