diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 3e6bade41..722a1d04f 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -305,29 +305,20 @@ class UserController extends CRUDController } } - - /** - * @param User $user - * @return \Symfony\Component\Form\Form - */ - private function createEditLocationForm() - { - return $this->createForm(UserCurrentLocationType::class) - ->add('submit', SubmitType::class, ['label' => 'Change current location']); - } - /** * Displays a form to edit the user current location. * - * @Route("/{_locale}/main/user/{id}/current-location/edit", name="chill_main_user_currentlocation_edit") + * @Route("/{_locale}/main/user/current-location/edit", name="chill_main_user_currentlocation_edit") */ - public function editCurrentLocationAction(User $user, Request $request) + public function editCurrentLocationAction(Request $request) { - $editForm = $this->createEditLocationForm(); - $editForm->handleRequest($request); + $user = $this->getUser(); + $form = $this->createForm(UserCurrentLocationType::class, $user) + ->add('submit', SubmitType::class, ['label' => 'Change current location']) + ->handleRequest($request); - if ($editForm->isSubmitted() && $editForm->isValid()) { - $currentLocation = $editForm->get('location')->getData(); + if ($form->isSubmitted() && $form->isValid()) { + $currentLocation = $form->get('currentLocation')->getData(); $user->setCurrentLocation($currentLocation); @@ -342,7 +333,7 @@ class UserController extends CRUDController return $this->render('@ChillMain/User/edit_current_location.html.twig', [ 'entity' => $user, - 'edit_form' => $editForm->createView() + 'edit_form' => $form->createView() ]); } } diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index fa24d987e..23dc99696 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -13,7 +13,7 @@ class UserCurrentLocationType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('location', EntityType::class, [ + ->add('currentLocation', EntityType::class, [ 'class' => Location::class, 'choice_label' => function (Location $entity) { return $entity->getName(); diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig index aa1f248ef..206c96642 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig @@ -6,7 +6,7 @@