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

Skip to content

Commit 3eff033

Browse files
committed
[Form][choice] avoid trans options for entity type.
1 parent cad9e0f commit 3eff033

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
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/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: 3 additions & 0 deletions
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,6 +232,7 @@ 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->setNormalizers(array(
@@ -240,6 +242,7 @@ public function configureOptions(OptionsResolver $resolver)
240242

241243
$resolver->setAllowedTypes(array(
242244
'choice_list' => array('null', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'),
245+
'translate_choices' => 'bool',
243246
));
244247
}
245248

0 commit comments

Comments
 (0)
0