mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
user: add change location for user in user menu
This commit is contained in:
parent
5905038425
commit
480e02af01
@ -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.
|
* 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();
|
$user = $this->getUser();
|
||||||
$editForm->handleRequest($request);
|
$form = $this->createForm(UserCurrentLocationType::class, $user)
|
||||||
|
->add('submit', SubmitType::class, ['label' => 'Change current location'])
|
||||||
|
->handleRequest($request);
|
||||||
|
|
||||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$currentLocation = $editForm->get('location')->getData();
|
$currentLocation = $form->get('currentLocation')->getData();
|
||||||
|
|
||||||
$user->setCurrentLocation($currentLocation);
|
$user->setCurrentLocation($currentLocation);
|
||||||
|
|
||||||
@ -342,7 +333,7 @@ class UserController extends CRUDController
|
|||||||
|
|
||||||
return $this->render('@ChillMain/User/edit_current_location.html.twig', [
|
return $this->render('@ChillMain/User/edit_current_location.html.twig', [
|
||||||
'entity' => $user,
|
'entity' => $user,
|
||||||
'edit_form' => $editForm->createView()
|
'edit_form' => $form->createView()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class UserCurrentLocationType extends AbstractType
|
|||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('location', EntityType::class, [
|
->add('currentLocation', EntityType::class, [
|
||||||
'class' => Location::class,
|
'class' => Location::class,
|
||||||
'choice_label' => function (Location $entity) {
|
'choice_label' => function (Location $entity) {
|
||||||
return $entity->getName();
|
return $entity->getName();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<h1>{{ 'Edit my current location'|trans }}</h1>
|
<h1>{{ 'Edit my current location'|trans }}</h1>
|
||||||
|
|
||||||
{{ form_start(edit_form) }}
|
{{ form_start(edit_form) }}
|
||||||
{{ form_row(edit_form.location) }}
|
{{ form_row(edit_form.currentLocation) }}
|
||||||
|
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li class="cancel">
|
<li class="cancel">
|
||||||
|
@ -38,28 +38,37 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
{
|
{
|
||||||
$this->tokenStorage = $tokenStorage;
|
$this->tokenStorage = $tokenStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
||||||
{
|
{
|
||||||
if ($this->tokenStorage->getToken()->getUser() instanceof User) {
|
if ($this->tokenStorage->getToken()->getUser() instanceof User) {
|
||||||
|
$menu
|
||||||
|
->addChild(
|
||||||
|
'Change location',
|
||||||
|
['route' => 'chill_main_user_currentlocation_edit']
|
||||||
|
)
|
||||||
|
->setExtras([
|
||||||
|
'order' => 99999999997
|
||||||
|
]);
|
||||||
$menu
|
$menu
|
||||||
->addChild(
|
->addChild(
|
||||||
'Change password',
|
'Change password',
|
||||||
[ 'route' => 'change_my_password']
|
['route' => 'change_my_password']
|
||||||
)
|
)
|
||||||
->setExtras([
|
->setExtras([
|
||||||
'order' => 99999999998
|
'order' => 99999999998
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu
|
$menu
|
||||||
->addChild(
|
->addChild(
|
||||||
'Logout',
|
'Logout',
|
||||||
[
|
[
|
||||||
'route' => 'logout'
|
'route' => 'logout'
|
||||||
])
|
]
|
||||||
|
)
|
||||||
->setExtras([
|
->setExtras([
|
||||||
'order'=> 99999999999,
|
'order' => 99999999999,
|
||||||
'icon' => 'power-off'
|
'icon' => 'power-off'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,10 @@ Flags: Drapeaux
|
|||||||
User jobs: Métiers
|
User jobs: Métiers
|
||||||
|
|
||||||
# user page for current location
|
# user page for current location
|
||||||
|
Current location: Localisation actuelle
|
||||||
Edit my current location: Éditer ma localisation actuelle
|
Edit my current location: Éditer ma localisation actuelle
|
||||||
Change current location: Changer ma localisation actuelle
|
Change current location: Changer ma localisation actuelle
|
||||||
|
Change location: Changer ma localisation
|
||||||
Current location successfully updated: Localisation actuelle mise à jour
|
Current location successfully updated: Localisation actuelle mise à jour
|
||||||
|
|
||||||
#admin section for circles (old: scopes)
|
#admin section for circles (old: scopes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user