user: refine display of location name (as usual, service injection does not work)

This commit is contained in:
nobohan 2021-11-17 14:12:22 +01:00
parent 480e02af01
commit 593817f12e
2 changed files with 20 additions and 1 deletions

View File

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

View File

@ -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