Commit 3bf78387 authored by Julien Fastré's avatar Julien Fastré

fix deprecations in closingMotive

parent 7227b89d
...@@ -7,6 +7,8 @@ use Symfony\Component\Form\FormBuilderInterface; ...@@ -7,6 +7,8 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; 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 * A type to add a closing motive
...@@ -16,16 +18,18 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; ...@@ -16,16 +18,18 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class ClosingMotiveType extends AbstractType 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->translatableStringHelper = $translatableStringHelper;
$this->locale = $request->getLocale();
}
} }
public function getBlockPrefix() public function getBlockPrefix()
{ {
return 'closing_motive'; return 'closing_motive';
} }
...@@ -37,17 +41,14 @@ class ClosingMotiveType extends AbstractType ...@@ -37,17 +41,14 @@ class ClosingMotiveType extends AbstractType
public function configureOptions(OptionsResolver $resolver) 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( $resolver->setDefaults(array(
'class' => 'ChillPersonBundle:AccompanyingPeriod\ClosingMotive', 'class' => ClosingMotive::class,
'empty_data' => null, 'empty_data' => null,
'placeholder' => 'Choose a motive', 'placeholder' => 'Choose a motive',
'choice_label' => 'name['.$this->locale.']' 'choice_label' => function(ClosingMotive $cm) {
return $this->translatableStringHelper
->localize($cm->getName());
}
) )
); );
} }
......
...@@ -11,9 +11,8 @@ services: ...@@ -11,9 +11,8 @@ services:
chill.person.accompanying_period_closing_motive: chill.person.accompanying_period_closing_motive:
class: Chill\PersonBundle\Form\Type\ClosingMotiveType class: Chill\PersonBundle\Form\Type\ClosingMotiveType
scope: request
arguments: arguments:
- "@request" - "@chill.main.helper.translatable_string"
tags: tags:
- { name: form.type, alias: closing_motive } - { name: form.type, alias: closing_motive }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment