From 0e18a3ada92bda913eb0d750b4d54c832568ffd4 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 15 Oct 2021 13:13:00 +0200 Subject: [PATCH] adding location hidden field in Calendar formType --- .../ChillCalendarBundle/Form/CalendarType.php | 17 ++++++++++++++++- .../Resources/views/Calendar/edit.html.twig | 7 +++++-- .../Resources/views/Calendar/new.html.twig | 9 ++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index 990f7ea59..f6e4d2baa 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -2,6 +2,7 @@ namespace Chill\CalendarBundle\Form; +use Chill\MainBundle\Entity\Location; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -155,7 +156,7 @@ class CalendarType extends AbstractType } )) ; - + $builder->add('calendarRange', HiddenType::class); $builder->get('calendarRange') ->addModelTransformer(new CallbackTransformer( @@ -178,6 +179,20 @@ class CalendarType extends AbstractType )) ; + $builder->add('location', HiddenType::class) + ->get('location') + ->addModelTransformer(new CallbackTransformer( + function (?Location $location): string { + if (null === $location) { + return ''; + } + return $location->getId(); + }, + function (?string $id): Location { + return $this->om->getRepository(Location::class)->findOneBy(['id' => (int) $id]); + } + )) + ; // $builder->add('invites', HiddenType::class); // $builder->get('invites') diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig index c4b33e82e..d67202920 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig @@ -38,7 +38,10 @@ {{ form_row(form.calendarRange) }} {% endif %} -.. location +{%- if form.location is defined -%} + {{ form_row(form.location) }} +
+{% endif %} {%- if form.comment is defined -%} {{ form_row(form.comment) }} @@ -56,7 +59,7 @@