user: correct dependency injection for form for locationType and userCurrentLocation

This commit is contained in:
nobohan 2021-11-18 11:26:14 +01:00
parent 11b82f7468
commit be92ac4a08
4 changed files with 24 additions and 27 deletions

View File

@ -15,15 +15,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
final class LocationFormType extends AbstractType final class LocationFormType extends AbstractType
{ {
// private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
// /** /**
// * @param TranslatableStringHelper $translatableStringHelper * @param TranslatableStringHelper $translatableStringHelper
// */ */
// public function __construct(TranslatableStringHelper $translatableStringHelper) public function __construct(TranslatableStringHelper $translatableStringHelper)
// { {
// $this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
// } }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
@ -38,8 +38,7 @@ final class LocationFormType extends AbstractType
]; ];
}, },
'choice_label' => function (EntityLocationType $entity) { 'choice_label' => function (EntityLocationType $entity) {
//return $this->translatableStringHelper->localize($entity->getTitle()); //TODO not working. Cannot pass smthg in the constructor return $this->translatableStringHelper->localize($entity->getTitle());
return $entity->getTitle()['fr'];
}, },
]) ])
->add('name', TextType::class) ->add('name', TextType::class)

View File

@ -3,7 +3,7 @@
namespace Chill\MainBundle\Form; namespace Chill\MainBundle\Form;
use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Location;
// use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -12,15 +12,15 @@ use Symfony\Component\Form\FormBuilderInterface;
class UserCurrentLocationType extends AbstractType class UserCurrentLocationType extends AbstractType
{ {
// private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
// /** /**
// * @param TranslatableStringHelper $translatableStringHelper * @param TranslatableStringHelper $translatableStringHelper
// */ */
// public function __construct(TranslatableStringHelper $translatableStringHelper) public function __construct(TranslatableStringHelper $translatableStringHelper)
// { {
// $this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
// } }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
@ -29,9 +29,8 @@ class UserCurrentLocationType extends AbstractType
'class' => Location::class, 'class' => Location::class,
'choice_label' => function (Location $entity) { 'choice_label' => function (Location $entity) {
return $entity->getName() ? return $entity->getName() ?
$entity->getLocationType()->getTitle()['fr'] . ' ' . $entity->getName() : $this->translatableStringHelper->localize($entity->getLocationType()->getTitle()) . ' ' . $entity->getName() :
//$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()); //TODO does not work $this->translatableStringHelper->localize($entity->getLocationType()->getTitle());
$entity->getLocationType()->getTitle()['fr'];
}, },
]); ]);
} }

View File

@ -140,10 +140,10 @@ services:
autoconfigure: true autoconfigure: true
autowire: true autowire: true
Chill\MainBundle\Form\Type\LocationFormType: Chill\MainBundle\Form\LocationFormType:
autowire: true autowire: true
autoconfigure: true autoconfigure: true
Chill\MainBundle\Form\Type\UserCurrentLocationType: Chill\MainBundle\Form\UserCurrentLocationType:
autowire: true autowire: true
autoconfigure: true autoconfigure: true

View File

@ -206,8 +206,7 @@ Location list: Liste des localisations
Location type: Type de localisation Location type: Type de localisation
Phonenumber1: Numéro de téléphone Phonenumber1: Numéro de téléphone
Phonenumber2: Autre numéro de téléphone Phonenumber2: Autre numéro de téléphone
Configure location: Configuration des localisations Configure location and location type: Configuration des localisations
Configure location type: Configuration des types de localisations
# circles / scopes # circles / scopes
Choose the circle: Choisir le cercle Choose the circle: Choisir le cercle