8000 Reflected the change of the choice_value option in the Upgrade inform… · symfony/symfony@28675c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28675c9

Browse files
committed
Reflected the change of the choice_value option in the Upgrade information
1 parent 2b8c9f8 commit 28675c9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

UPGRADE-2.8.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ Form
186186
}
187187
```
188188

189+
* In Symfony 2.7 a small BC break was introduced with the new choices_as_values
190+
option. In order to have the choice values populated to the html value attribute
191+
you had to define the choice_value option. This is now not any more needed.
192+
193+
Before:
194+
195+
```php
196+
$form->add('status', 'choice', array(
197+
'choices' => array(
198+
'Enabled' => Status::ENABLED,
199+
'Disabled' => Status::DISABLED,
200+
'Ignored' => Status::IGNORED,
201+
),
202+
'choices_as_values' => true,
203+
// important if you rely on your option value attribute (e.g. for JavaScript)
204+
// this will keep the same functionality as before
205+
'choice_value' => function ($choice) {
206+
return $choice;
207+
},
208+
));
209+
```
210+
211+
After (Symfony 2.8+):
212+
213+
```php
214+
$form->add('status', ChoiceType::class, array(
215+
'choices' => array(
216+
'Enabled' => Status::ENABLED,
217+
'Disabled' => Status::DISABLED,
218+
'Ignored' => Status::IGNORED,
219+
),
220+
'choices_as_values' => true
221+
));
222+
```
223+
189224
* Returning type instances from `FormTypeInterface::getParent()` is deprecated
190225
and will not be supported anymore in Symfony 3.0. Return the fully-qualified
191226
class name of the parent type class instead.

UPGRADE-3.0.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,42 @@ UPGRADE FROM 2.x to 3.0
365365
}
366366
}
367367
```
368+
369+
* In Symfony 2.7 a small BC break was introduced with the new choices_as_values
370+
option. In order to have the choice values populated to the html value attribute
371+
you had to define the choice_value option. This is now not any more needed.
372+
373+
Before:
8000 374+
375+
```php
376+
$form->add('status', 'choice', array(
377+
'choices' => array(
378+
'Enabled' => Status::ENABLED,
379+
'Disabled' => Status::DISABLED,
380+
'Ignored' => Status::IGNORED,
381+
),
382+
// choices_as_values defaults to true in Symfony 3.0
383+
// and setting it to anything else is deprecated as of 3.0
384+
'choices_as_values' => true,
385+
// important if you rely on your option value attribute (e.g. for JavaScript)
386+
// this will keep the same functionality as before
387+
'choice_value' => function ($choice) {
388+
return $choice;
389+
},
390+
));
391+
```
392+
393+
After:
394+
395+
```php
396+
$form->add('status', ChoiceType::class, array(
397+
'choices' => array(
398+
'Enabled' => Status::ENABLED,
399+
'Disabled' => Status::DISABLED,
400+
'Ignored' => Status::IGNORED,
401+
)
402+
));
403+
```
368404

369405
* The `request` service was removed. You must inject the `request_stack`
370406
service instead.

0 commit comments

Comments
 (0)
0