mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
fix: show validation message when closing course
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user