new participation: add optional return_path to POST request

This commit is contained in:
Tchama 2019-05-02 16:19:28 +02:00
parent bd19110ecd
commit 8c3c9c4a1f
2 changed files with 34 additions and 9 deletions

View File

@ -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'

View File

@ -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()
))