diff --git a/Form/CustomFieldType.php b/Form/CustomFieldType.php index 209ac1f8e..7e1733877 100644 --- a/Form/CustomFieldType.php +++ b/Form/CustomFieldType.php @@ -16,6 +16,7 @@ use Doctrine\Common\Persistence\ObjectManager; use Chill\CustomFieldsBundle\Service\CustomFieldProvider; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; use Chill\MainBundle\Form\Type\TranslatableStringFormType; +use Chill\MainBundle\Templating\TranslatableStringHelper; class CustomFieldType extends AbstractType @@ -25,8 +26,12 @@ class CustomFieldType extends AbstractType * @var CustomFieldProvider */ private $customFieldProvider; - - private $culture = 'fr'; + + /** + * + * @var TranslatableStringHelper + */ + private $translatableStringHelper; /** * @var ObjectManager @@ -34,11 +39,14 @@ class CustomFieldType extends AbstractType private $om; - public function __construct(CustomFieldProvider $compiler, - ObjectManager $om) - { + public function __construct( + CustomFieldProvider $compiler, + ObjectManager $om, + TranslatableStringHelper $translatableStringHelper + ) { $this->customFieldProvider = $compiler; $this->om = $om; + $this->translatableStringHelper = $translatableStringHelper; } /** * @param FormBuilderInterface $builder @@ -60,7 +68,9 @@ class CustomFieldType extends AbstractType if ($options['group_widget'] === 'entity') { $builder->add('customFieldsGroup', EntityType::class, array( 'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup', - 'property' => 'name['.$this->culture.']' + 'choice_label' => function($g) { + return $this->translatableStringHelper->localize($g->getName()); + } )); } elseif ($options['group_widget'] === 'hidden') { $builder->add('customFieldsGroup', HiddenType::class); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index a9be9193d..028f4eaa3 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -12,6 +12,7 @@ services: arguments: - "@chill.custom_field.provider" - "@doctrine.orm.entity_manager" + - '@chill.main.helper.translatable_string' tags: - { name: 'form.type', alias: 'custom_field_choice' }