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);
}
$form = $this->createForm(CalendarType::class, $entity, [
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
$form = $this->createForm(CalendarType::class, $entity);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->persist($entity);

View File

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

View File

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

View File

@ -107,6 +107,8 @@ final class CalendarTypeTest extends TypeTestCase
$this->assertEquals(8, $calendar->getCalendarRange()->getId());
$this->assertEquals(9, $calendar->getLocation()->getId());
$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()

View File

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

View File

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