Fix: fix the loading of pickCenterType when no regroupments exists and

defaults of SocialWorkTypeFilter
This commit is contained in:
Julien Fastré 2023-06-23 13:04:13 +02:00
parent 9073f118db
commit 9978b6a6e4
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 9 additions and 24 deletions

View File

@ -20,38 +20,23 @@ use Symfony\Component\Form\FormInterface;
use function array_key_exists; use function array_key_exists;
use function count; use function count;
class ExportPickCenterDataMapper implements DataMapperInterface final readonly class ExportPickCenterDataMapper implements DataMapperInterface
{ {
public function __construct( public function mapDataToForms($viewData, $forms): void
private RegroupmentRepository $regroupmentRepository,
) {
}
public function mapDataToForms($data, $forms): void
{ {
if (null === $data) { if (null === $viewData) {
return; return;
} }
/** @var array<string, FormInterface> $form */ /** @var array<string, FormInterface> $form */
$form = iterator_to_array($forms); $form = iterator_to_array($forms);
$pickedRegroupment = []; $form['center']->setData($viewData);
foreach ($this->regroupmentRepository->findAll() as $regroupment) { // NOTE: we do not map back the regroupments
/** @phpstan-ignore-next-line */
[$contained, $notContained] = $regroupment->getCenters()->partition(static fn (int $id, Center $center): bool => false);
if (0 === count($notContained)) {
$pickedRegroupment[] = $regroupment;
}
}
$form['regroupment']->setData([]);
$form['center']->setData($data);
} }
public function mapFormsToData($forms, &$data): void public function mapFormsToData($forms, &$viewData): void
{ {
/** @var array<string, FormInterface> $forms */ /** @var array<string, FormInterface> $forms */
$forms = iterator_to_array($forms); $forms = iterator_to_array($forms);
@ -71,6 +56,6 @@ class ExportPickCenterDataMapper implements DataMapperInterface
} }
} }
$data = array_values($centers); $viewData = array_values($centers);
} }
} }

View File

@ -77,7 +77,7 @@ final class PickCenterType extends AbstractType
]); ]);
} }
$builder->setDataMapper(new ExportPickCenterDataMapper($this->regroupmentRepository)); $builder->setDataMapper(new ExportPickCenterDataMapper());
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View File

@ -113,7 +113,7 @@ class SocialWorkTypeFilter implements FilterInterface
public function getFormDefaultData(): array public function getFormDefaultData(): array
{ {
return ['action_type' => '', 'goal' => '', 'result' => '']; return ['action_type' => [], 'goal' => [], 'result' => []];
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array