From cf7f8a929b01cf2f14bc485e2a3904d7b9c30f94 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 24 Mar 2016 18:03:45 +0100 Subject: [PATCH] Allow the modification of event + adding the prefix chill_even to all the route --- Controller/EventController.php | 35 ++++++++++---------- Controller/ParticipationController.php | 4 +-- Resources/config/routing/event.yml | 19 +++++------ Resources/views/Event/edit.html.twig | 6 ++-- Resources/views/Event/index.html.twig | 8 ++--- Resources/views/Event/list.html.twig | 8 ++--- Resources/views/Event/new.html.twig | 2 +- Resources/views/Event/show.html.twig | 2 +- Resources/views/Participation/edit.html.twig | 2 +- Resources/views/Participation/new.html.twig | 2 +- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 126a6b86a..56c2b2d7f 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -42,7 +42,7 @@ class EventController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('event_show', array('event_id' => $entity->getId()))); + return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId()))); } return $this->render('ChillEventBundle:Event:new.html.twig', array( @@ -61,7 +61,7 @@ class EventController extends Controller private function createCreateForm(Event $entity) { $form = $this->createForm(EventType::class, $entity, array( - 'action' => $this->generateUrl('event_create'), + 'action' => $this->generateUrl('chill_event__event_create'), 'method' => 'POST' )); @@ -152,18 +152,18 @@ class EventController extends Controller * Displays a form to edit an existing Event entity. * */ - public function editAction($id) + public function editAction($event_id) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); } $editForm = $this->createEditForm($entity); - $deleteForm = $this->createDeleteForm($id); + $deleteForm = $this->createDeleteForm($event_id); return $this->render('ChillEventBundle:Event:edit.html.twig', array( 'entity' => $entity, @@ -181,11 +181,12 @@ class EventController extends Controller */ private function createEditForm(Event $entity) { - $form = $this->createForm(new EventType(), $entity, array( - 'action' => $this->generateUrl('event_update', array('id' => $entity->getId())), + $form = $this->createForm(EventType::class, $entity, array( + 'action' => $this->generateUrl('chill_event__event_update', array('event_id' => $entity->getId())), 'method' => 'PUT', )); + $form->add('submit', 'submit', array('label' => 'Update')); return $form; @@ -194,24 +195,24 @@ class EventController extends Controller * Edits an existing Event entity. * */ - public function updateAction(Request $request, $id) + public function updateAction(Request $request, $event_id) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); } - $deleteForm = $this->createDeleteForm($id); + $deleteForm = $this->createDeleteForm($event_id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); if ($editForm->isValid()) { $em->flush(); - return $this->redirect($this->generateUrl('event_edit', array('id' => $id))); + return $this->redirect($this->generateUrl('chill_event__event_edit', array('event_id' => $event_id))); } return $this->render('ChillEventBundle:Event:edit.html.twig', array( @@ -224,14 +225,14 @@ class EventController extends Controller * Deletes a Event entity. * */ - public function deleteAction(Request $request, $id) + public function deleteAction(Request $request, $event_id) { - $form = $this->createDeleteForm($id); + $form = $this->createDeleteForm($event_id); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository('ChillEventBundle:Event')->find($id); + $entity = $em->getRepository('ChillEventBundle:Event')->find($event_id); if (!$entity) { throw $this->createNotFoundException('Unable to find Event entity.'); @@ -247,14 +248,14 @@ class EventController extends Controller /** * Creates a form to delete a Event entity by id. * - * @param mixed $id The entity id + * @param mixed $event_id The event id * * @return \Symfony\Component\Form\Form The form */ - private function createDeleteForm($id) + private function createDeleteForm($event_id) { return $this->createFormBuilder() - ->setAction($this->generateUrl('event_delete', array('id' => $id))) + ->setAction($this->generateUrl('chill_event__event_delete', array('event_id' => $event_id))) ->setMethod('DELETE') ->add('submit', 'submit', array('label' => 'Delete')) ->getForm() diff --git a/Controller/ParticipationController.php b/Controller/ParticipationController.php index 8cf065706..9024ea253 100644 --- a/Controller/ParticipationController.php +++ b/Controller/ParticipationController.php @@ -68,7 +68,7 @@ class ParticipationController extends Controller 'The participation was created' )); - return $this->redirectToRoute('event_show', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $participation->getEvent()->getId() )); } @@ -205,7 +205,7 @@ class ParticipationController extends Controller 'The participation was updated' )); - return $this->redirectToRoute('event_show', array( + return $this->redirectToRoute('chill_event__event_show', array( 'event_id' => $participation->getEvent()->getId() )); diff --git a/Resources/config/routing/event.yml b/Resources/config/routing/event.yml index ecbcf144f..25b39a5c6 100644 --- a/Resources/config/routing/event.yml +++ b/Resources/config/routing/event.yml @@ -8,11 +8,11 @@ chill_event_list_most_recent: label: Events icons: [calendar] -event_show: +chill_event__event_show: path: /{event_id}/show defaults: { _controller: "ChillEventBundle:Event:show" } -event_new: +chill_event__event_new: path: /new defaults: { _controller: "ChillEventBundle:Event:new" } options: @@ -22,22 +22,21 @@ event_new: label: Add an event icons: [plus, calendar-o] - -event_create: +chill_event__event_create: path: /create defaults: { _controller: "ChillEventBundle:Event:create" } methods: POST -event_edit: - path: /{id}/edit +chill_event__event_edit: + path: /{event_id}/edit defaults: { _controller: "ChillEventBundle:Event:edit" } -event_update: - path: /{id}/update +chill_event__event_update: + path: /{event_id}/update defaults: { _controller: "ChillEventBundle:Event:update" } methods: [POST, PUT] -event_delete: - path: /{id}/delete +chill_event__event_delete: + path: /{event_id}/delete defaults: { _controller: "ChillEventBundle:Event:delete" } methods: [POST, DELETE] diff --git a/Resources/views/Event/edit.html.twig b/Resources/views/Event/edit.html.twig index 733f7332c..1d365f28a 100644 --- a/Resources/views/Event/edit.html.twig +++ b/Resources/views/Event/edit.html.twig @@ -1,13 +1,13 @@ -{% extends '::base.html.twig' %} +{% extends 'ChillEventBundle::layout.html.twig' %} -{% block body -%} +{% block event_content -%}

Event edit

{{ form(edit_form) }}