Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function profileEditAction(Request $request) {
- $user = $this->getUser();
- if (!is_object($user) || !$user instanceof UserInterface) {
- $this->redirectToRoute('fos_user_security_login');
- }
- $profile = $user->getProfile();
- if (!($profile instanceof Profile)) {
- $profile = new Profile();
- $profile->setUser($user);
- }
- $em = $this->getDoctrine()->getManager();
- $originalPhone = new ArrayCollection();
- foreach ($profile->getPhonenumbers() as $phone) {
- $originalPhone->add($phone);
- }
- $form = $this->createForm(ProfileEditType::class, $profile);
- $form->handleRequest($request);
- if ($form->isValid()) {
- $profile = $form->getData();
- foreach ($originalPhone as $phone) {
- if (false === $profile->getPhonenumbers()->contains($phone)) {
- $phone->getProfile()->removeElement($phone);
- $em->persist($phone);
- }
- }
- $em->persist($profile);
- $em->flush();
- $url = $this->generateUrl('fos_user_profile_show');
- $response = new RedirectResponse($url);
- return $response;
- }
- return $this->render(
- '@App/Profile/profile-edit.html.twig',
- ['form' => $form->createView()]
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement