8000 bug #37521 [Form] Fix ChoiceType translation domain (VincentLanglet) · phpfour/symfony@a56f648 · GitHub
[go: up one dir, main page]

Skip to content

Commit a56f648

Browse files
bug symfony#37521 [Form] Fix ChoiceType translation domain (VincentLanglet)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [Form] Fix ChoiceType translation domain | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? |no | Tickets | Fix #... | License | MIT | Doc PR | symfony/symfony-docs#... When using ``` ->add('foo', ChoiceType::class, [ 'label' => 'label', 'translation_domain' => false, 'choices' => [ 'choice.no' => false, 'choice.yes' => true, ], 'choice_translation_domain' => 'messages', 'expanded' => true, 'required' => false, 'placeholder' => false, ]); ``` I discovered that the choices was not translated. Seems like it's because the subForm is using the `translation_domain` instead of the `choice_translation_domain`. Commits ------- 2effda7 [Form] Fix ChoiceType translation domain
2 parents ae91683 + 2effda7 commit a56f648

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ private function addSubForm(FormBuilderInterface $builder, $name, ChoiceView $ch
386386
'value' => $choiceView->value,
387387
'label' => $choiceView->label,
388388
'attr' => $choiceView->attr,
389-
'translation_domain' => $options['translation_domain'],
389+
'translation_domain' => $options['choice_translation_domain'],
390390
'block_name' => 'entry',
391391
];
392392

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,24 @@ public function testStripLeadingUnderscoresAndDigitsFromId()
19941994
$this->assertEquals('_09name', $view->vars['full_name']);
19951995
}
19961996

1997+
public function testSubFormTranslationDomain()
1998+
{
1999+
$form = $this->factory->create(static::TESTED_TYPE, null, [
2000+
'label' => 'label',
2001+
'translation_domain' => 'label_translation_domain',
2002+
'choices' => [
2003+
'choice1' => true,
2004+
'choice2' => false,
2005+
],
2006+
'choice_translation_domain' => 'choice_translation_domain',
2007+
'expanded' => true,
2008+
])->createView();
2009+
2010+
$this->assertCount(2, $form->children);
2011+
$this->assertSame('choice_translation_domain', $form->children[0]->vars['translation_domain']);
2012+
$this->assertSame('choice_translation_domain', $form->children[1]->vars['translation_domain']);
2013+
}
2014+
19972015
/**
19982016
* @dataProvider provideTrimCases
19992017
*/

0 commit comments

Comments
 (0)
0