mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix: fix the loading of pickCenterType when no regroupments exists and
defaults of SocialWorkTypeFilter
This commit is contained in:
parent
9073f118db
commit
9978b6a6e4
@ -20,38 +20,23 @@ use Symfony\Component\Form\FormInterface;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
final readonly class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RegroupmentRepository $regroupmentRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function mapDataToForms($data, $forms): void
|
||||
public function mapDataToForms($viewData, $forms): void
|
||||
{
|
||||
if (null === $data) {
|
||||
if (null === $viewData) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var array<string, FormInterface> $form */
|
||||
$form = iterator_to_array($forms);
|
||||
|
||||
$pickedRegroupment = [];
|
||||
$form['center']->setData($viewData);
|
||||
|
||||
foreach ($this->regroupmentRepository->findAll() as $regroupment) {
|
||||
/** @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);
|
||||
// NOTE: we do not map back the regroupments
|
||||
}
|
||||
|
||||
public function mapFormsToData($forms, &$data): void
|
||||
public function mapFormsToData($forms, &$viewData): void
|
||||
{
|
||||
/** @var array<string, FormInterface> $forms */
|
||||
$forms = iterator_to_array($forms);
|
||||
@ -71,6 +56,6 @@ class ExportPickCenterDataMapper implements DataMapperInterface
|
||||
}
|
||||
}
|
||||
|
||||
$data = array_values($centers);
|
||||
$viewData = array_values($centers);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ final class PickCenterType extends AbstractType
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->setDataMapper(new ExportPickCenterDataMapper($this->regroupmentRepository));
|
||||
$builder->setDataMapper(new ExportPickCenterDataMapper());
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
@ -113,7 +113,7 @@ class SocialWorkTypeFilter implements FilterInterface
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['action_type' => '', 'goal' => '', 'result' => ''];
|
||||
return ['action_type' => [], 'goal' => [], 'result' => []];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
|
Loading…
x
Reference in New Issue
Block a user