mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
fix deprecations in closingMotive
This commit is contained in:
@@ -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());
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user