diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index f9190857c..596d2bbdf 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -150,7 +150,7 @@ final class PersonController extends AbstractController )); } - public function editAction($person_id) + public function editAction($person_id, Request $request) { $person = $this->_getPerson($person_id); @@ -163,57 +163,33 @@ final class PersonController extends AbstractController $form = $this->createForm(PersonType::class, $person, array( - "action" => $this->generateUrl('chill_person_general_update', - array("person_id" => $person_id)), "cFGroup" => $this->getCFGroup() ) ); - return $this->render('ChillPersonBundle:Person:edit.html.twig', - array('person' => $person, 'form' => $form->createView())); - } - - public function updateAction($person_id, Request $request) - { - $person = $this->_getPerson($person_id); - - if ($person === null) { - return $this->createNotFoundException(); - } - - $this->denyAccessUnlessGranted('CHILL_PERSON_UPDATE', $person, - 'You are not allowed to edit this person'); - - $form = $this->createForm(PersonType::class, $person, - array("cFGroup" => $this->getCFGroup())); - - if ($request->getMethod() === 'POST') { - $form->handleRequest($request); - - if ( ! $form->isValid() ) { - $this->get('session') - ->getFlashBag()->add('error', $this->translator - ->trans('This form contains errors')); - - return $this->render('ChillPersonBundle:Person:edit.html.twig', - array('person' => $person, - 'form' => $form->createView())); - } + $form->handleRequest($request); + if ($form->isSubmitted() && !$form->isValid()) { + $this->get('session') + ->getFlashBag()->add('error', $this->translator + ->trans('This form contains errors')); + } elseif ($form->isSubmitted() && $form->isValid()) { $this->get('session')->getFlashBag() - ->add('success', - $this->get('translator') - ->trans('The person data has been updated') - ); + ->add('success', + $this->get('translator') + ->trans('The person data has been updated') + ); $this->em->flush(); - $url = $this->generateUrl('chill_person_view', array( + return $this->redirectToRoute('chill_person_view', [ 'person_id' => $person->getId() - )); - - return $this->redirect($url); + ]); } + + + return $this->render('ChillPersonBundle:Person:edit.html.twig', + array('person' => $person, 'form' => $form->createView())); } /**