logic moved to controller instead of form

This commit is contained in:
Julie Lenaerts 2021-10-07 10:56:10 +02:00
parent b510d6a7f5
commit 9d6958a835
2 changed files with 5 additions and 8 deletions

View File

@ -174,6 +174,10 @@ class ActivityController extends AbstractController
$activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
->find($activityType_id); ->find($activityType_id);
if (isset($activityType) && !$activityType->isActive()) {
throw new \InvalidArgumentException('Activity type must be active');
}
$activityData = null; $activityData = null;
if ($request->query->has('activityData')) { if ($request->query->has('activityData')) {
$activityData = $request->query->get('activityData'); $activityData = $request->query->get('activityData');
@ -256,7 +260,6 @@ class ActivityController extends AbstractController
'role' => new Role('CHILL_ACTIVITY_CREATE'), 'role' => new Role('CHILL_ACTIVITY_CREATE'),
'activityType' => $entity->getType(), 'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod, 'accompanyingPeriod' => $accompanyingPeriod,
'edit' => false
])->handleRequest($request); ])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
@ -367,7 +370,6 @@ class ActivityController extends AbstractController
'role' => new Role('CHILL_ACTIVITY_UPDATE'), 'role' => new Role('CHILL_ACTIVITY_UPDATE'),
'activityType' => $entity->getType(), 'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod, 'accompanyingPeriod' => $accompanyingPeriod,
'edit' => true
])->handleRequest($request); ])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {

View File

@ -93,10 +93,6 @@ class ActivityType extends AbstractType
/** @var \Chill\ActivityBundle\Entity\ActivityType $activityType */ /** @var \Chill\ActivityBundle\Entity\ActivityType $activityType */
$activityType = $options['activityType']; $activityType = $options['activityType'];
if (!$activityType->isActive() && $options['edit'] !== true) {
throw new \InvalidArgumentException('Activity type must be active');
}
// TODO revoir la gestion des center au niveau du form des activité. // TODO revoir la gestion des center au niveau du form des activité.
if ($options['center']) { if ($options['center']) {
$builder->add('scope', ScopePickerType::class, [ $builder->add('scope', ScopePickerType::class, [
@ -378,12 +374,11 @@ class ActivityType extends AbstractType
]); ]);
$resolver $resolver
->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod', 'edit']) ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod'])
->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center']) ->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center'])
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role') ->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role')
->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class) ->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class)
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']) ->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null'])
->setAllowedTypes('edit', 'bool')
; ;
} }