diff --git a/Form/Type/ClosingMotiveType.php b/Form/Type/ClosingMotiveType.php index 604272b95..00285582a 100644 --- a/Form/Type/ClosingMotiveType.php +++ b/Form/Type/ClosingMotiveType.php @@ -7,6 +7,8 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; /** * A type to add a closing motive @@ -16,16 +18,18 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; class ClosingMotiveType extends AbstractType { - private $locale; - - public function __construct(Request $request = NULL) + /** + * + * @var TranslatableStringHelper + */ + protected $translatableStringHelper; + + public function __construct(TranslatableStringHelper $translatableStringHelper) { - if ($request !== NULL) { - $this->locale = $request->getLocale(); - } + $this->translatableStringHelper = $translatableStringHelper; } - public function getBlockPrefix() + public function getBlockPrefix() { return 'closing_motive'; } @@ -37,17 +41,14 @@ class ClosingMotiveType extends AbstractType public function configureOptions(OptionsResolver $resolver) { - if ($this->locale === NULL) { - throw new \LogicException('the locale should be defined and is extracted ' - . 'from the \'request\' service. Maybe was this service ' - . 'unaccessible ?'); - } - $resolver->setDefaults(array( - 'class' => 'ChillPersonBundle:AccompanyingPeriod\ClosingMotive', + 'class' => ClosingMotive::class, 'empty_data' => null, 'placeholder' => 'Choose a motive', - 'choice_label' => 'name['.$this->locale.']' + 'choice_label' => function(ClosingMotive $cm) { + return $this->translatableStringHelper + ->localize($cm->getName()); + } ) ); } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 7a96b25d1..cfa5c618b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -11,9 +11,8 @@ services: chill.person.accompanying_period_closing_motive: class: Chill\PersonBundle\Form\Type\ClosingMotiveType - scope: request arguments: - - "@request" + - "@chill.main.helper.translatable_string" tags: - { name: form.type, alias: closing_motive }