From d604c6b7d0145221e4324ee050f330ed92d63740 Mon Sep 17 00:00:00 2001 From: upskaling Date: Thu, 22 Jan 2026 13:51:15 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20champ=20'ann=C3=A9e'=20au=20formul?= =?UTF-8?q?aire=20d'=C3=A9v=C3=A9nement=20et=20mise=20=C3=A0=20jour=20du?= =?UTF-8?q?=20mod=C3=A8le=20pour=20g=C3=A9rer=20sa=20valeur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/AppBundle/Event/Form/EventType.php | 9 +++++++++ sources/AppBundle/Event/Model/Event.php | 14 ++++++++++++++ .../Event/Model/Repository/EventRepository.php | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/sources/AppBundle/Event/Form/EventType.php b/sources/AppBundle/Event/Form/EventType.php index 2de33ee76..cd998b51f 100644 --- a/sources/AppBundle/Event/Form/EventType.php +++ b/sources/AppBundle/Event/Form/EventType.php @@ -15,6 +15,8 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints as Assert; @@ -168,6 +170,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void new Assert\File(mimeTypes: 'application/pdf'), ], ]) + ->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void { + /** @var Event $event */ + $event = $event->getData(); + if ($event->getDateStart() !== null) { + $event->setYear($event->getDateStart()->format('Y')); + } + }) ; } diff --git a/sources/AppBundle/Event/Model/Event.php b/sources/AppBundle/Event/Model/Event.php index b1f78805b..a18e4debd 100644 --- a/sources/AppBundle/Event/Model/Event.php +++ b/sources/AppBundle/Event/Model/Event.php @@ -27,6 +27,8 @@ class Event implements NotifyPropertyInterface private ?DateTime $dateEnd = null; + private ?string $year = null; + /** * @var DateTime */ @@ -187,6 +189,18 @@ public function setDateEnd(?DateTime $dateEnd): self return $this; } + public function getYear(): ?string + { + return $this->year; + } + + public function setYear(?string $year): self + { + $this->propertyChanged('year', $this->year, $year); + $this->year = $year; + return $this; + } + /** * @return DateTime */ diff --git a/sources/AppBundle/Event/Model/Repository/EventRepository.php b/sources/AppBundle/Event/Model/Repository/EventRepository.php index 0d4d58ec0..6fd13e137 100644 --- a/sources/AppBundle/Event/Model/Repository/EventRepository.php +++ b/sources/AppBundle/Event/Model/Repository/EventRepository.php @@ -323,6 +323,11 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor 'unserialize' => ['unSerializeUseFormat' => false], ], ]) + ->addField([ + 'columnName' => 'annee', + 'fieldName' => 'year', + 'type' => 'string', + ]) ->addField([ 'columnName' => 'date_fin_appel_projet', 'fieldName' => 'dateEndCallForProjects',