Fixed: [calendar] add a return path to calendar doc

See https://gitlab.com/Chill-Projet/chill-bundles/-/issues/23
This commit is contained in:
Julien Fastré 2022-11-25 17:02:12 +01:00
parent 788b1e9eeb
commit 9b32ce53c8
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -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(),
]
)
)
);
}