From 8c3c9c4a1fb0edea03bd4fe19c4f883d25bbaa19 Mon Sep 17 00:00:00 2001 From: Tchama Date: Thu, 2 May 2019 16:19:28 +0200 Subject: [PATCH] new participation: add optional return_path to POST request --- Controller/EventController.php | 14 ++++++++++--- Controller/ParticipationController.php | 29 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 08eee5590..5be3717cd 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -171,10 +171,11 @@ class EventController extends Controller $entity = new Event(); $entity->setCenter($center); - $form = $this->createCreateForm($entity); + $form = $this->createCreateForm($entity); $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) + { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); @@ -425,7 +426,14 @@ class EventController extends Controller $builder->add('person_id', HiddenType::class, array( 'data' => $person->getId() )); - + + $builder->add('return_path', HiddenType::class, array( + 'data' => $this->generateUrl('chill_event__list_by_person', array( + 'person_id' => $person->getId() + )) + )); + + $builder->add('submit', SubmitType::class, array( 'label' => 'Subscribe an event' diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 4c597a818..10c7d6f6f 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -35,6 +35,7 @@ use Symfony\Component\Form\Extension\Core\Type\CollectionType; */ class ParticipationController extends Controller { + /** * Show a form to add a participation * @@ -43,9 +44,12 @@ class ParticipationController extends Controller * on this, the appropriate layout and form. * * @param Request $request + * @return Response */ public function newAction(Request $request) { + dump('coucou'); + // test the request is correct try { $this->testRequest($request); @@ -123,12 +127,16 @@ class ParticipationController extends Controller */ protected function newSingle(Request $request) { + + $returnPath = $request->query->get('return_path') ? + $request->query->get('return_path') : null; + $participation = $this->handleRequest($request, new Participation(), false); $this->denyAccessUnlessGranted(ParticipationVoter::CREATE, $participation, 'The user is not allowed to create this participation'); - $form = $this->createCreateForm($participation); + $form = $this->createCreateForm($participation, $returnPath); return $this->render('ChillEventBundle:Participation:new.html.twig', array( 'form' => $form->createView(), @@ -267,9 +275,16 @@ class ParticipationController extends Controller 'The participation was created' )); - return $this->redirectToRoute('chill_event__event_show', array( - 'event_id' => $participation->getEvent()->getId() - )); + if ($request->query->get('return_path')) + { + return $this->redirect($request->query->get('return_path')); + + } else { + return $this->redirectToRoute('chill_event__event_show', array( + 'event_id' => $participation->getEvent()->getId() + )); + } + } return $this->render('ChillEventBundle:Participation:new.html.twig', array( @@ -390,15 +405,17 @@ class ParticipationController extends Controller } /** - * * @param Participation $participation + * @param null $return_path * @return \Symfony\Component\Form\FormInterface */ - public function createCreateForm(Participation $participation) + public function createCreateForm(Participation $participation, $return_path = null) { + $form = $this->createForm(ParticipationType::class, $participation, array( 'event_type' => $participation->getEvent()->getType(), 'action' => $this->generateUrl('chill_event_participation_create', array( + 'return_path' => $return_path, 'event_id' => $participation->getEvent()->getId(), 'person_id' => $participation->getPerson()->getId() ))