From b510d6a7f5bf593c65bff81472de80ddad8f4413 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 6 Oct 2021 14:07:26 +0200 Subject: [PATCH 1/3] option added to distinguish between edit and new action so that modification of activity with uactive type is possible --- .../Controller/ActivityController.php | 2 ++ src/Bundle/ChillActivityBundle/Form/ActivityType.php | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index a454626b7..80bf8bb04 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -256,6 +256,7 @@ class ActivityController extends AbstractController 'role' => new Role('CHILL_ACTIVITY_CREATE'), 'activityType' => $entity->getType(), 'accompanyingPeriod' => $accompanyingPeriod, + 'edit' => false ])->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -366,6 +367,7 @@ class ActivityController extends AbstractController 'role' => new Role('CHILL_ACTIVITY_UPDATE'), 'activityType' => $entity->getType(), 'accompanyingPeriod' => $accompanyingPeriod, + 'edit' => true ])->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 8c8fb45a9..3906fadd6 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -93,7 +93,7 @@ class ActivityType extends AbstractType /** @var \Chill\ActivityBundle\Entity\ActivityType $activityType */ $activityType = $options['activityType']; - if (!$activityType->isActive()) { + if (!$activityType->isActive() && $options['edit'] !== true) { throw new \InvalidArgumentException('Activity type must be active'); } @@ -101,7 +101,9 @@ class ActivityType extends AbstractType if ($options['center']) { $builder->add('scope', ScopePickerType::class, [ 'center' => $options['center'], - 'role' => $options['role'] + 'role' => $options['role'], + // TODO make required again once scope and rights are fixed + 'required' => false ]); } @@ -376,11 +378,12 @@ class ActivityType extends AbstractType ]); $resolver - ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod']) + ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod', 'edit']) ->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') ; } From 9d6958a8358d31a13313accf8cdfbea5ac28725c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 7 Oct 2021 10:56:10 +0200 Subject: [PATCH 2/3] logic moved to controller instead of form --- .../ChillActivityBundle/Controller/ActivityController.php | 6 ++++-- src/Bundle/ChillActivityBundle/Form/ActivityType.php | 7 +------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 80bf8bb04..8a4a228eb 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -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()) { diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 3906fadd6..5a711408c 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -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') ; } From 48e59bac79ffabc907e9de0d3834e4593114e13e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 7 Oct 2021 15:50:35 +0200 Subject: [PATCH 3/3] changelog updated --- src/Bundle/ChillActivityBundle/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bundle/ChillActivityBundle/CHANGELOG.md b/src/Bundle/ChillActivityBundle/CHANGELOG.md index 871ead4bd..6261aa1db 100644 --- a/src/Bundle/ChillActivityBundle/CHANGELOG.md +++ b/src/Bundle/ChillActivityBundle/CHANGELOG.md @@ -27,3 +27,4 @@ Version 1.5.5 ============= - [activity] replace dropdown for selecting reasons and use chillEntity for reason rendering +- fix bug: error when trying to edit activity of which the type has been deactivated