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

View File

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

View File

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

View File

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