fix behaviour of CalendarType in Controller and add field users to CalendarType

This commit is contained in:
Julien Fastré 2022-05-20 19:44:28 +02:00
parent 67fad5d764
commit 2b770036a5
6 changed files with 21 additions and 12 deletions

View File

@ -295,9 +295,8 @@ class CalendarController extends AbstractController
$entity->setAccompanyingPeriod($accompanyingPeriod); $entity->setAccompanyingPeriod($accompanyingPeriod);
} }
$form = $this->createForm(CalendarType::class, $entity, [ $form = $this->createForm(CalendarType::class, $entity);
'accompanyingPeriod' => $accompanyingPeriod, $form->handleRequest($request);
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$em->persist($entity); $em->persist($entity);

View File

@ -129,6 +129,10 @@ class CalendarType extends AbstractType
->addModelTransformer($this->partiesToIdDataTransformer); ->addModelTransformer($this->partiesToIdDataTransformer);
*/ */
$builder->add('users', HiddenType::class);
$builder->get('users')
->addModelTransformer($this->idToUsersDataTransformer);
$builder->add('calendarRange', HiddenType::class); $builder->add('calendarRange', HiddenType::class);
$builder->get('calendarRange') $builder->get('calendarRange')
->addModelTransformer($this->calendarRangeDataTransformer); ->addModelTransformer($this->calendarRangeDataTransformer);

View File

@ -1,10 +1,6 @@
--- ---
services: services:
chill.calendar.form.type.calendar: Chill\CalendarBundle\Form\:
class: Chill\CalendarBundle\Form\CalendarType resource: './../../Form'
arguments: autowire: true
- "@chill.main.helper.translatable_string" autoconfigure: true
- "@doctrine.orm.entity_manager"
tags:
- { name: form.type, alias: chill_calendarbundle_calendar }

View File

@ -107,6 +107,8 @@ final class CalendarTypeTest extends TypeTestCase
$this->assertEquals(8, $calendar->getCalendarRange()->getId()); $this->assertEquals(8, $calendar->getCalendarRange()->getId());
$this->assertEquals(9, $calendar->getLocation()->getId()); $this->assertEquals(9, $calendar->getLocation()->getId());
$this->assertEquals(true, $calendar->getSendSMS()); $this->assertEquals(true, $calendar->getSendSMS());
$this->assertContains(2, $calendar->getUsers()->map(function (User $u) { return $u->getId(); }));
$this->assertContains(3, $calendar->getUsers()->map(function (User $u) { return $u->getId(); }));
} }
protected function getExtensions() protected function getExtensions()

View File

@ -88,6 +88,10 @@ class IdToEntityDataTransformer implements DataTransformerInterface
return implode(',', $ids); return implode(',', $ids);
} }
if (null === $value) {
return '';
}
$id = call_user_func($this->getId, $value); $id = call_user_func($this->getId, $value);
if (null === $id) { if (null === $id) {

View File

@ -143,3 +143,7 @@ services:
Chill\MainBundle\Form\Type\LocationFormType: ~ Chill\MainBundle\Form\Type\LocationFormType: ~
Chill\MainBundle\Form\WorkflowStepType: ~ Chill\MainBundle\Form\WorkflowStepType: ~
Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer: ~
Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer: ~
Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer: ~