fix saving person

This commit is contained in:
Julien Fastré 2021-11-08 15:31:19 +01:00
parent ec6828f128
commit 9247cd3546

View File

@ -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); $person = $this->_getPerson($person_id);
@ -163,43 +163,17 @@ final class PersonController extends AbstractController
$form = $this->createForm(PersonType::class, $person, $form = $this->createForm(PersonType::class, $person,
array( array(
"action" => $this->generateUrl('chill_person_general_update',
array("person_id" => $person_id)),
"cFGroup" => $this->getCFGroup() "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); $form->handleRequest($request);
if ( ! $form->isValid() ) { if ($form->isSubmitted() && !$form->isValid()) {
$this->get('session') $this->get('session')
->getFlashBag()->add('error', $this->translator ->getFlashBag()->add('error', $this->translator
->trans('This form contains errors')); ->trans('This form contains errors'));
} elseif ($form->isSubmitted() && $form->isValid()) {
return $this->render('ChillPersonBundle:Person:edit.html.twig',
array('person' => $person,
'form' => $form->createView()));
}
$this->get('session')->getFlashBag() $this->get('session')->getFlashBag()
->add('success', ->add('success',
$this->get('translator') $this->get('translator')
@ -208,12 +182,14 @@ final class PersonController extends AbstractController
$this->em->flush(); $this->em->flush();
$url = $this->generateUrl('chill_person_view', array( return $this->redirectToRoute('chill_person_view', [
'person_id' => $person->getId() 'person_id' => $person->getId()
)); ]);
return $this->redirect($url);
} }
return $this->render('ChillPersonBundle:Person:edit.html.twig',
array('person' => $person, 'form' => $form->createView()));
} }
/** /**