security->isGranted(PersonVoter::UPDATE, $person)) { throw new AccessDeniedHttpException('You are not allowed to edit this person.'); } $form = $this->formFactory->create( PersonType::class, $person, ['cFGroup' => $this->customFieldsDefaultGroupRepository->findOneByEntity(Person::class)?->getCustomFieldsGroup()] ); $form->handleRequest($request); if ($form->isSubmitted() && !$form->isValid()) { $session ->getFlashBag()->add('error', new TranslatableMessage('This form contains errors')); } elseif ($form->isSubmitted() && $form->isValid()) { $this->entityManager->flush(); $session->getFlashBag()->add('success', new TranslatableMessage('The person data has been updated')); return new RedirectResponse( $this->urlGenerator->generate('chill_person_view', ['person_id' => $person->getId()]) ); } return new Response($this->twig->render('@ChillPerson/Person/edit.html.twig', [ 'form' => $form->createView(), 'person' => $person, ])); } }