Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Use choice_translation_domain in BooleanType (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and OskarStark committed Oct 4, 2016
1 parent 1b12f54 commit 26c05fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Form/Type/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public function configureOptions(OptionsResolver $resolver)
},
);

// SF 2.7+ BC
// NEXT_MAJOR: Remove this "if" (when requirement of Symfony is >= 2.7)
if (method_exists('Symfony\Component\Form\AbstractType', 'configureOptions')) {
$choices = array_flip($choices);

$defaultOptions['choice_translation_domain'] = 'SonataCoreBundle';

// choice_as_value options is not needed in SF 3.0+
if (method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions')) {
$defaultOptions['choices_as_values'] = true;
Expand Down
6 changes: 6 additions & 0 deletions Tests/Form/Type/BooleanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function testOptions()
$expectedOptions = array(
'transform' => false,
'catalogue' => 'SonataCoreBundle',
'choice_translation_domain' => 'SonataCoreBundle',
'choices_as_values' => true,
'translation_domain' => 'fooTrans',
'choices' => array(1 => 'foo_yes', 2 => 'foo_no'),
Expand All @@ -173,6 +174,11 @@ public function testOptions()
unset($expectedOptions['choices_as_values']);
}

// NEXT_MAJOR: Remove this block (when requirement of Symfony is >= 2.7)
if (!method_exists('Symfony\Component\Form\AbstractType', 'configureOptions')) {
unset($expectedOptions['choice_translation_domain']);
}

$this->assertSame($expectedOptions, $resolvedOptions);
}

Expand Down

0 comments on commit 26c05fd

Please sign in to comment.