From 39e6f353740e63e14e2af532f7674f2c30bc73fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 31 Aug 2026 15:56:12 +0200 Subject: [PATCH] fix: cleanup stale teamer pickups --- src/Form/TeamerProfileType.php | 37 +++++++++++++++++++ .../teamer/modal_info.html.twig | 9 ++++- .../administrative/teamer/profile.html.twig | 9 ++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Form/TeamerProfileType.php b/src/Form/TeamerProfileType.php index e48179f..d6c411d 100644 --- a/src/Form/TeamerProfileType.php +++ b/src/Form/TeamerProfileType.php @@ -2,6 +2,7 @@ namespace App\Form; +use App\BusProNet\DataProvider\PickupDataProvider; use App\Entity\Teamer; use App\Enum\MealPreference; use App\Model\UploadSessionDto; @@ -13,12 +14,18 @@ use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\EnumType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class TeamerProfileType extends AbstractType { + public function __construct(private readonly PickupDataProvider $pickups) + { + } + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder @@ -101,6 +108,36 @@ class TeamerProfileType extends AbstractType 'choice_label' => 'label', ]) ; + + // The stored pickup ids are free-form and never reconciled with the + // BusProNet pickup base data, so drop ids that no longer resolve (and + // duplicates) before the collection builds its rows. Skipped while the + // base data is unavailable so a failed fetch cannot wipe real data. + // Priority 1 so this runs before the CollectionType's ResizeFormListener + // turns the array into child rows. + $builder->get('pickups')->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { + $ids = $event->getData(); + + if (!is_array($ids)) { + return; + } + + $known = $this->pickups->getAll(); + + if ([] === $known) { + return; + } + + $normalized = []; + foreach ($ids as $id) { + $id = (int) $id; + if (isset($known[$id]) && !in_array($id, $normalized, true)) { + $normalized[] = $id; + } + } + + $event->setData($normalized); + }, 1); } public function buildView(FormView $view, FormInterface $form, array $options): void diff --git a/templates/administrative/teamer/modal_info.html.twig b/templates/administrative/teamer/modal_info.html.twig index 761ba40..8fd1df7 100644 --- a/templates/administrative/teamer/modal_info.html.twig +++ b/templates/administrative/teamer/modal_info.html.twig @@ -29,9 +29,16 @@ Zustiege