From 593817f12e15c27eaa1c4b76b0aaeeb9ff631226 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 17 Nov 2021 14:12:22 +0100 Subject: [PATCH] user: refine display of location name (as usual, service injection does not work) --- .../Form/UserCurrentLocationType.php | 17 ++++++++++++++++- .../ChillMainBundle/config/services/form.yaml | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index 23dc99696..607b9c31e 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -3,6 +3,7 @@ namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\Location; +// use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -10,13 +11,27 @@ use Symfony\Component\Form\FormBuilderInterface; class UserCurrentLocationType extends AbstractType { + + // private TranslatableStringHelper $translatableStringHelper; + + // /** + // * @param TranslatableStringHelper $translatableStringHelper + // */ + // public function __construct(TranslatableStringHelper $translatableStringHelper) + // { + // $this->translatableStringHelper = $translatableStringHelper; + // } + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('currentLocation', EntityType::class, [ 'class' => Location::class, 'choice_label' => function (Location $entity) { - return $entity->getName(); + return $entity->getName() ? + $entity->getName() : + //$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()); //TODO does not work + $entity->getLocationType()->getTitle()['fr']; }, ]); } diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 27d018229..b20f9e226 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -141,5 +141,9 @@ services: autowire: true Chill\MainBundle\Form\Type\LocationFormType: + autowire: true + autoconfigure: true + + Chill\MainBundle\Form\Type\UserCurrentLocationType: autowire: true autoconfigure: true \ No newline at end of file