8000 [Form][choice] avoid trans options for entity type. · symfony/symfony@cc32189 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc32189

Browse files
committed
[Form][choice] avoid trans options for entity type.
1 parent 17ad6fd commit cc32189

File tree

9 files changed

+47
-9
lines changed

9 files changed

+47
-9
lines changed

UPGRADE-2.7.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ Router
1515
`foo%bar%2` which would be compiled to `$foo % $bar % 2` in 2.6
1616
but in 2.7 you would get an error if `bar` parameter
1717
doesn't exist or unexpected result otherwise.
18-
18+
1919
Form
2020
----
2121

2222
* In form types and extension overriding the "setDefaultOptions" of the
2323
AbstractType or AbstractExtensionType has been deprecated in favor of
2424
overriding the new "configureOptions" method.
2525

26-
The method "setDefaultOptions(OptionsResolverInterface $resolver)" will
26+
The method "setDefaultOptions(OptionsResolverInterface $resolver)" will
2727
be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)".
2828

2929
Before:
3030

3131
```php
3232
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
33-
33+
3434
class TaskType extends AbstractType
3535
{
3636
// ...
@@ -47,7 +47,7 @@ Form
4747

4848
```php
4949
use Symfony\Component\OptionsResolver\OptionsResolver;
50-
50+
5151
class TaskType extends AbstractType
5252
{
5353
// ...
@@ -60,6 +60,27 @@ Form
6060
}
6161
```
6262

63+
* The ability to translate Doctrine type entries by the translator component
64+
is now disabled by default and to enable it you must explicitly set the option
65+
"translate_choices" to "true".
66+
67+
Before:
68+
69+
```
70+
$form->add('products', 'entity', array(
71+
'class' => 'AppBundle/Entity/Product',
72+
));
73+
```
74+
75+
After:
76+
77+
```
78+
$form->add('products', 'entity', array(
79+
'class' => 'AppBundle/Entity/Product',
80+
'translate_choices' => true,
81+
));
82+
```
83+
6384
Serializer
6485
----------
6586

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function configureOptions(OptionsResolver $resolver)
171171
'choices' => null,
172172
'choice_list' => $choiceList,
173173
'group_by' => null,
174+
'translate_choices' => false,
174175
));
175176

176177
$resolver->setRequired(array('class'));

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
{{- block('choice_widget_options') -}}
8080
</optgroup>
8181
{%- else -%}
82-
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
82+
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ translate_choices is sameas(false) ? choice.label : choice.label|trans({}, translation_domain) }}</option>
8383
{%- endif -%}
8484
{% endfor %}
8585
{%- endblock choice_widget_options -%}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/phpunit-bridge": "~2.7|~3.0.0",
2424
"symfony/asset": "~2.7|~3.0.0",
2525
"symfony/finder": "~2.3|~3.0.0",
26-
"symfony/form": "~2.6|~3.0.0",
26+
"symfony/form": "~2.7|~3.0.0",
2727
"symfony/http-kernel": "~2.3|~3.0.0",
2828
"symfony/intl": "~2.3|~3.0.0",
2929
"symfony/routing": "~2.2|~3.0.0",

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
77
</optgroup>
88
<?php else: ?>
9-
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
9+
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translate_choices ? $translatorHelper->trans($choice->label, array(), $translation_domain) : $choice->label) ?></option>
1010
<?php endif ?>
1111
<?php endforeach ?>

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"symfony/finder": "~2.0,>=2.0.5|~3.0.0",
4343
"symfony/intl": "~2.3|~3.0.0",
4444
"symfony/security": "~2.6|~3.0.0",
45-
"symfony/form": "~2.6|~3.0.0",
45+
"symfony/form": "~2.7|~3.0.0",
4646
"symfony/class-loader": "~2.1|~3.0.0",
4747
"symfony/expression-language": "~2.6|~3.0.0",
4848
"symfony/process": "~2.0,>=2.0.5|~3.0.0",

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.7.0
55
-----
66

7+
* added options "translate_choices" to ChoiceType.
78
* deprecated the overwriting of AbstractType::setDefaultOptions() in favor of overwriting AbstractType::configureOptions().
89
* deprecated the overwriting of AbstractTypeExtension::setDefaultOptions() in favor of overwriting AbstractTypeExtension::configureOptions().
910

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
102102
'choices' => $options['choice_list']->getRemainingViews(),
103103
'separator' => '-------------------',
104104
'placeholder' => null,
105+
'translate_choices' => $options['translate_choices'],
105106
));
106107

107108
// The decision, whether a choice is selected, is potentially done
@@ -231,12 +232,16 @@ public function configureOptions(OptionsResolver $resolver)
231232
// is manually set to an object.
232233
// See https://github.com/symfony/symfony/pull/5582
233234
'data_class' => null,
235+
'translate_choices' => true,
234236
));
235237

236238
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
237239
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
238240

239-
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'));
241+
$resolver->setAllowedTypes(array(
242+
'choice_list' => array('null', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'),
243+
'translate_choices' => 'bool',
244+
));
240245
}
241246

242247
/**

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ public function testPassExpandedToView()
10111011
$this->assertTrue($view->vars['expanded']);
10121012
}
10131013

1014+
public function testPassTranslateChoicesToView()
1015+
{
1016+
$form = $this->factory->create('choice', null, array(
1017+
'choices' => $this->choices,
1018+
));
1019+
$view = $form->createView();
1020+
1021+
$this->assertTrue($view->vars['translate_choices']);
1022+
}
1023+
10141024
public function testPlaceholderIsNullByDefaultIfRequired()
10151025
{
10161026
$form = $this->factory->create('choice', null, array(

0 commit comments

Comments
 (0)
0