mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fixes for settign a localisation
This commit is contained in:
parent
69384a84d1
commit
764bb6a21f
@ -3,6 +3,7 @@
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Repository\LocationRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@ -11,15 +12,16 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class UserCurrentLocationType extends AbstractType
|
||||
{
|
||||
|
||||
private LocationRepository $locationRepository;
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
*/
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper, LocationRepository $locationRepository)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->locationRepository = $locationRepository;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
@ -27,11 +29,14 @@ class UserCurrentLocationType extends AbstractType
|
||||
$builder
|
||||
->add('currentLocation', EntityType::class, [
|
||||
'class' => Location::class,
|
||||
'choices' => $this->locationRepository->findByPublicLocations(),
|
||||
'choice_label' => function (Location $entity) {
|
||||
return $entity->getName() ?
|
||||
$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()) . ' ' . $entity->getName() :
|
||||
$entity->getName().' ('.$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()).')' :
|
||||
$this->translatableStringHelper->localize($entity->getLocationType()->getTitle());
|
||||
},
|
||||
'placeholder' => 'Pick a location',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -18,4 +18,14 @@ class LocationRepository extends ServiceEntityRepository
|
||||
{
|
||||
parent::__construct($registry, Location::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch locations which are selectable for users
|
||||
*
|
||||
* @return Location[]
|
||||
*/
|
||||
public function findByPublicLocations()
|
||||
{
|
||||
return $this->findBy(['active' => true, 'availableForUsers' => true]);
|
||||
}
|
||||
}
|
||||
|
@ -3,21 +3,19 @@
|
||||
{% block title %}{{ 'Edit my current location'|trans }}{% endblock %}
|
||||
|
||||
{% block content -%}
|
||||
<h1>{{ 'Edit my current location'|trans }}</h1>
|
||||
<div class="col-md-10 col-xxl">
|
||||
<h1>{{ 'Edit my current location'|trans }}</h1>
|
||||
|
||||
{{ form_start(edit_form) }}
|
||||
{{ form_row(edit_form.currentLocation) }}
|
||||
{{ form_start(edit_form) }}
|
||||
{{ form_row(edit_form.currentLocation) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li class="cancel">
|
||||
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">
|
||||
{{ 'Cancel'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(edit_form.submit, { 'attr': { 'class': 'btn btn-edit' } } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li>
|
||||
{{ form_widget(edit_form.submit, { 'attr': { 'class': 'btn btn-edit' } } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ form_end(edit_form) }}
|
||||
{{ form_end(edit_form) }}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -20,35 +20,37 @@ namespace Chill\MainBundle\Routing\MenuBuilder;
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TokenStorageInterface
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
private Security $security;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage)
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
||||
{
|
||||
if ($this->tokenStorage->getToken()->getUser() instanceof User) {
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if ($user instanceof User) {
|
||||
|
||||
if (null !== $user->getCurrentLocation()) {
|
||||
$locationTextMenu = $user->getCurrentLocation()->getName();
|
||||
} else {
|
||||
$locationTextMenu = 'Set a location';
|
||||
}
|
||||
|
||||
$menu
|
||||
->addChild(
|
||||
'Change location',
|
||||
$locationTextMenu,
|
||||
['route' => 'chill_main_user_currentlocation_edit']
|
||||
)
|
||||
->setExtras([
|
||||
'order' => 99999999997
|
||||
'order' => -9999999,
|
||||
'icon' => 'map-marker'
|
||||
]);
|
||||
$menu
|
||||
->addChild(
|
||||
|
@ -7,8 +7,8 @@ services:
|
||||
resource: '../../Routing/MenuBuilder'
|
||||
|
||||
Chill\MainBundle\Routing\MenuBuilder\UserMenuBuilder:
|
||||
arguments:
|
||||
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: 'chill.menu_builder' }
|
||||
|
||||
|
@ -184,8 +184,9 @@ User jobs: Métiers
|
||||
Current location: Localisation actuelle
|
||||
Edit my current location: Éditer ma localisation actuelle
|
||||
Change current location: Changer ma localisation actuelle
|
||||
Change location: Changer ma localisation
|
||||
Set a location: Indiquer une localisation
|
||||
Current location successfully updated: Localisation actuelle mise à jour
|
||||
Pick a location: Choisir un lieu
|
||||
|
||||
#admin section for circles (old: scopes)
|
||||
List circles: Cercles
|
||||
|
Loading…
x
Reference in New Issue
Block a user