From 9b32ce53c8e4bce0b8543eaa15a24d09b4a9384c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Nov 2022 17:02:12 +0100 Subject: [PATCH] Fixed: [calendar] add a return path to calendar doc See https://gitlab.com/Chill-Projet/chill-bundles/-/issues/23 --- .../Controller/CalendarDocController.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php index cdadb65e5..ba7951225 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarDocController.php @@ -16,6 +16,7 @@ use Chill\CalendarBundle\Security\Voter\CalendarVoter; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use RuntimeException; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -47,7 +48,7 @@ class CalendarDocController /** * @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template") */ - public function pickTemplate(Calendar $calendar): Response + public function pickTemplate(Calendar $calendar, Request $request): Response { if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) { throw new AccessDeniedException('Not authorized to see this calendar'); @@ -60,14 +61,21 @@ class CalendarDocController if (1 === $number) { $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); + if ($request->query->has('returnPath')) { + $returnPathParam = ['returnPath' => $request->query->get('returnPath')]; + } + return new RedirectResponse( $this->urlGenerator->generate( 'chill_docgenerator_generate_from_template', - [ - 'template' => $templates[0]->getId(), - 'entityClassName' => Calendar::class, - 'entityId' => $calendar->getId(), - ] + array_merge( + $returnPathParam ?? [], + [ + 'template' => $templates[0]->getId(), + 'entityClassName' => Calendar::class, + 'entityId' => $calendar->getId(), + ] + ) ) ); }