mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix: show validation message when closing course
This commit is contained in:
parent
da8422d0a7
commit
f23be44b9a
@ -12,6 +12,7 @@ and this project adheres to
|
||||
|
||||
<!-- write down unreleased development here -->
|
||||
* Use the user.label in accompanying course banner, instead of username;
|
||||
* fix: show validation message when closing accompanying course;
|
||||
|
||||
## Test releases
|
||||
|
||||
|
@ -22,9 +22,12 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
@ -42,18 +45,22 @@ class AccompanyingCourseController extends Controller
|
||||
|
||||
private AccompanyingPeriodWorkRepository $workRepository;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
SerializerInterface $serializer,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
ValidatorInterface $validator,
|
||||
AccompanyingPeriodWorkRepository $workRepository,
|
||||
Registry $registry
|
||||
Registry $registry,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->serializer = $serializer;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->validator = $validator;
|
||||
$this->workRepository = $workRepository;
|
||||
$this->registry = $registry;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +71,9 @@ class AccompanyingCourseController extends Controller
|
||||
{
|
||||
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $accompanyingCourse);
|
||||
|
||||
$form = $this->createForm(AccompanyingCourseType::class, $accompanyingCourse);
|
||||
$form = $this->createForm(AccompanyingCourseType::class, $accompanyingCourse, [
|
||||
'validation_groups' => [AccompanyingPeriod::STEP_CLOSED]
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
@ -74,11 +83,7 @@ class AccompanyingCourseController extends Controller
|
||||
$workflow = $this->registry->get($accompanyingCourse);
|
||||
|
||||
if ($workflow->can($accompanyingCourse, 'close')) {
|
||||
$errors = $this->validator->validate($accompanyingCourse, null, [$accompanyingCourse::STEP_CLOSED]);
|
||||
|
||||
if (count($errors) > 0) {
|
||||
return $this->json($errors, 422);
|
||||
}
|
||||
$workflow->apply($accompanyingCourse, 'close');
|
||||
|
||||
$em->flush();
|
||||
@ -86,6 +91,15 @@ class AccompanyingCourseController extends Controller
|
||||
return $this->redirectToRoute('chill_person_accompanying_course_index', [
|
||||
'accompanying_period_id' => $accompanyingCourse->getId(),
|
||||
]);
|
||||
} else {
|
||||
/** @var ConstraintViolationListInterface $errors */
|
||||
$errors = $this->validator->validate($accompanyingCourse, null, [$accompanyingCourse::STEP_CLOSED]);
|
||||
$this->addFlash('error', $this->translator->trans('It is not possible to close this course'));
|
||||
|
||||
foreach ($errors as $e) {
|
||||
/** @var ConstraintViolationInterface $e */
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +169,7 @@ Update accompanying period: Mettre à jour une période d'accompagnement
|
||||
'Period not opened': "La période d'accompagnement n'a pas été ouverte"
|
||||
"Period not opened : form is invalid": "La période n'a pas été ouverte: le formulaire est invalide."
|
||||
'Closing motive': 'Motif de clôture'
|
||||
Close accompanying course: Clôturer le parcours
|
||||
'Person details': 'Détails de la personne'
|
||||
'Update details for %name%': 'Modifier détails de %name%'
|
||||
An accompanying period ends: Une periode d'accompagnement se clôture
|
||||
|
Loading…
x
Reference in New Issue
Block a user