From 9e285404a1834bb626cf787dc16dca555a10c689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gardien?= Date: Wed, 30 Oct 2024 15:33:58 +0100 Subject: [PATCH] [Admin] Can not change donation to membership if no linked adherent --- src/Admin/DonationAdmin.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Admin/DonationAdmin.php b/src/Admin/DonationAdmin.php index 4e304b0627..a91a7510e3 100644 --- a/src/Admin/DonationAdmin.php +++ b/src/Admin/DonationAdmin.php @@ -138,7 +138,7 @@ protected function configureFormFields(FormMapper $form): void ->add('membership', CheckboxType::class, [ 'label' => 'Cotisation', 'required' => false, - 'disabled' => $donation->isMembership(), + 'disabled' => $donation->isMembership() || null === $donation->getDonator()?->getAdherent(), ]) ->add('code', null, [ 'label' => 'Code don', @@ -616,6 +616,18 @@ protected function preUpdate(object $object): void $this->handleAdherentMembership($object); } + /** + * @param Donation $object + */ + protected function postUpdate(object $object): void + { + parent::postUpdate($object); + + if ($adherent = $object->getDonator()?->getAdherent()) { + $this->refreshAdherent($adherent); + } + } + /** * @param Donation $object */ @@ -624,8 +636,7 @@ protected function postRemove(object $object): void parent::postRemove($object); if ($object->isMembership() && $adherent = $object->getDonator()?->getAdherent()) { - $this->adherentRepository->refreshLastDonationDate($adherent); - $this->dispatcher->dispatch(new UserEvent($adherent), UserEvents::USER_UPDATED_IN_ADMIN); + $this->refreshAdherent($adherent); } if ($object->hasFileUploaded()) { @@ -637,6 +648,12 @@ protected function postRemove(object $object): void } } + private function refreshAdherent(Adherent $adherent): void + { + $this->adherentRepository->refreshLastDonationDate($adherent); + $this->dispatcher->dispatch(new UserEvent($adherent), UserEvents::USER_UPDATED_IN_ADMIN); + } + protected function createNewInstance(): object { /** @var Donation $donation */