getUser(); $form = $this->createForm(UserEditProfilType::class , $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = $form->getData(); $em->flush(); $this->addFlash('success', "Votre profil a été modifié"); } return $this->render('profil/monprofil.html.twig', array ( 'form' => $form )); } #[Route("/preferences", name: "user_preferences")] public function mesPreferencesAction(Request $request, EntityManagerInterface $em, ProfileRepository $profileRepo): Response { $profile = $profileRepo->findByUser($this->getUser()); $form = $this->createForm(ProfileType::class , $profile); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $profile = $form->getData(); $em->flush(); $this->addFlash('success', "Les préférences ont été modifiées"); } return $this->render('profil/mespreferences.html.twig', [ 'form' => $form ]); } #[Route("/changeview", name: "user_changeview")] public function changeView(EntityManagerInterface $em): JsonResponse { /** @var \App\Entity\User $user */ $user = $this->getUser(); $profile = $user->getProfile(); if ($profile->getView() == Profile::$VIEW['liste']) { $profile->setView(Profile::$VIEW['vignette']); } else { $profile->setView(Profile::$VIEW['liste']); } $em->flush(); return $this->json($profile->getView()); } #[Route("/getview", name: "user_getview")] public function getView(): JsonResponse { /** @var \App\Entity\User $user */ $user = $this->getUser(); return $this->json($user->getProfile()->getView()); } }