user: add change location for user in user menu

This commit is contained in:
nobohan
2021-11-17 13:54:32 +01:00
parent 5905038425
commit 480e02af01
5 changed files with 28 additions and 26 deletions

View File

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