8000 bug #20886 [Form] DateIntervalType: Do not try to translate choices (… · symfony/symfony@e1e9479 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1e9479

Browse files
committed
bug #20886 [Form] DateIntervalType: Do not try to translate choices (ogizanagi)
This PR was merged into the 3.2 branch. Discussion ---------- [Form] DateIntervalType: Do not try to translate choices | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A When using choice widgets, the form type should not try to translate each options, otherwise, you'll get something like this: <img width="150" alt="screenshot 2016-12-12 a 23 37 09" src="https://cloud.githubusercontent.com/assets/2211145/21119721/25411620-c0c4-11e6-9848-95393d1d21c4.PNG"> <img width="1075" alt="screenshot 2016-12-12 a 23 37 23" src="https://cloud.githubusercontent.com/assets/2211145/21119722/2543ccf8-c0c4-11e6-9842-ae84dc895a0b.PNG"> Commits ------- b6831d2 [Form] DateIntervalType: Do not try to translate choices
2 parents a1a058b + b6831d2 commit e1e9479

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
102102
$childOptions[$part] = array();
103103
$childOptions[$part]['error_bubbling'] = true;
104104
if ('choice' === $options['widget']) {
105+
$childOptions[$part]['choice_translation_domain'] = false;
105106
$childOptions[$part]['choices'] = $options[$part];
106107
$childOptions[$part]['placeholder'] = $options['placeholder'][$part];
107108
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
1415
use Symfony\Component\Form\FormError;
1516
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
1617

@@ -364,4 +365,23 @@ public function testDateTypeChoiceErrorsBubbleUp()
364365
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
365366
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
366367
}
368+
public function testTranslationsAreDisabledForChoiceWidget()
369+
{
370+
$form = $this->factory->create(
371+
DateIntervalType::class,
372+
null,
373+
array(
374+
'widget' => 'choice',
375+
'with_hours' => true,
376+
'with_minutes' => true,
377+
'with_seconds' => true,
378+
)
379+
);
380+
$this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain'));
381+
$this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain'));
382+
$this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain'));
383+
$this->assertFalse($form->get('hours')->getConfig()->getOption('choice_translation_domain'));
384+
$this->assertFalse($form->get('minutes')->getConfig()->getOption('choice_translation_domain'));
385+
$this->assertFalse($form->get('seconds')->getConfig()->getOption('choice_translation_domain'));
386+
}
367387
}

0 commit comments

Comments
 (0)
0