Skip to content

Commit

Permalink
bug #20886 [Form] DateIntervalType: Do not try to translate choices (…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Dec 13, 2016
2 parents a1a058b + b6831d2 commit e1e9479
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -102,6 +102,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$childOptions[$part] = array();
$childOptions[$part]['error_bubbling'] = true;
if ('choice' === $options['widget']) {
$childOptions[$part]['choice_translation_domain'] = false;
$childOptions[$part]['choices'] = $options[$part];
$childOptions[$part]['placeholder'] = $options['placeholder'][$part];
}
Expand Down
Expand Up @@ -11,6 +11,7 @@

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

use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Test\TypeTestCase as TestCase;

Expand Down Expand Up @@ -364,4 +365,23 @@ public function testDateTypeChoiceErrorsBubbleUp()
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
}
public function testTranslationsAreDisabledForChoiceWidget()
{
$form = $this->factory->create(
DateIntervalType::class,
null,
array(
'widget' => 'choice',
'with_hours' => true,
'with_minutes' => true,
'with_seconds' => true,
)
);
$this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain'));
$this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain'));
$this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain'));
$this->assertFalse($form->get('hours')->getConfig()->getOption('choice_translation_domain'));
$this->assertFalse($form->get('minutes')->getConfig()->getOption('choice_translation_domain'));
$this->assertFalse($form->get('seconds')->getConfig()->getOption('choice_translation_domain'));
}
}

0 comments on commit e1e9479

Please sign in to comment.