mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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 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([]);
|
public function mapFormsToData($forms, &$viewData): void
|
||||||
$form['center']->setData($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mapFormsToData($forms, &$data): 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user