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

View File

@ -93,10 +93,6 @@ class ActivityType extends AbstractType
/** @var \Chill\ActivityBundle\Entity\ActivityType $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é.
if ($options['center']) {
$builder->add('scope', ScopePickerType::class, [
@ -378,12 +374,11 @@ class ActivityType extends AbstractType
]);
$resolver
->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod', 'edit'])
->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod'])
->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center'])
->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role')
->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class)
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null'])
->setAllowedTypes('edit', 'bool')
;
}