diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php index c52b7dd92..29b77a430 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Entity\Gender; +use Chill\MainBundle\Export\DataTransformerInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Repository\GenderRepository; @@ -27,7 +28,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; class GenderFilter implements ExportElementValidatedInterface, - FilterInterface + FilterInterface, + DataTransformerInterface { // inject gender repository and find the active genders so that you can pass them to the ChoiceType (ordered by ordering) public function __construct(private readonly TranslatorInterface $translator, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly GenderRepository $genderRepository) {} @@ -77,6 +79,26 @@ class GenderFilter implements ]); } + public function transformData(?array $before): array + { + $transformedData = $before; + + if (array_key_exists('accepted_genders', $before)) { + $genderMapping = [ + 'woman' => 2, + 'man' => 1, + 'both' => 3, + 'unknown' => null, + ]; + + $transformedData['accepted_genders_entity'] = array_map(function ($gender) use ($genderMapping) { + return $genderMapping[$gender] ?? null; + }, $before['accepted_genders']); + } + + return $transformedData; + } + public function getFormDefaultData(): array { return [];