fixes for settign a localisation

This commit is contained in:
2021-11-22 13:43:33 +01:00
parent 69384a84d1
commit 764bb6a21f
6 changed files with 52 additions and 36 deletions

View File

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