8000 minor #16849 Upgrade information for the choice_value option (peterrehm) · symfony/symfony@d1a8e50 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1a8e50

Browse files
minor #16849 Upgrade information for the choice_value option (peterrehm)
This PR was merged into the 2.8 branch. Discussion ---------- Upgrade information for the choice_value option | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Relates to #14825 and #14377. The behaviour was changed with #16681 so a not in the upgrade information makes sense to me. Commits ------- 28675c9 Reflected the change of the choice_value option in the Upgrade information
2 parents 2172054 + 28675c9 commit d1a8e50

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
@@ -200,6 +200,41 @@ Form
200200
}
201201
```
202202

203+
* In Symfony 2.7 a small BC break was introduced with the new choices_as_values
204+
option. In order to have the choice values populated to the html value attribute
205+
you had to define the choice_value option. This is now not any more needed.
206+
207+
Before:
208+
209+
```php
210+
$form->add('status', 'choice', array(
211+
'choices' => array(
212+
'Enabled' => Status::ENABLED,
213+
'Disabled' => Status::DISABLED,
214+
'Ignored' => Status::IGNORED,
215+
),
216+
'choices_as_values' => true,
217+
// important if you rely on your option value attribute (e.g. for JavaScript)
218+
// this will keep the same functionality as before
219+
'choice_value' => function ($choice) {
220+
return $choice;
221+
},
222+
));
223+
```
224+
225+
After (Symfony 2.8+):
226+
227+
```php
228+
$form->add('status', ChoiceType::class, array(
229+
'choices' => array(
230+
'Enabled' => Status::ENABLED,
231+
'Disabled' => Status::DISABLED,
232+
'Ignored' => Status::IGNORED,
233+
),
234+
'choices_as_values' => true
235+
));
236+
```
237+
203238
* Returning type instances from `FormTypeInterface::getParent()` is deprecated
204239
and will not be supported anymore in Symfony 3.0. Return the fully-qualified
205240
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:
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