option added to distinguish between edit and new action so that modification of activity with uactive type is possible

This commit is contained in:
Julie Lenaerts 2021-10-06 14:07:26 +02:00
parent ddbd6a9f23
commit b510d6a7f5
2 changed files with 8 additions and 3 deletions

View File

@ -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()) {

View File

@ -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')
;
}