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);
@ -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()));
}
/**