Skip to content

Commit a216951

Browse files
committed
minor symfony#7940 [Form] Fix choice keys and values for custom field types (michaelperrin)
This PR was submitted for the 3.2 branch but it was merged into the 2.7 branch instead (closes symfony#7940). Discussion ---------- [Form] Fix choice keys and values for custom field types Choices labels are defined as the keys of the array as of Symfony 3 (see symfony/symfony#14050). I prefered to keep the same parameters for the "Creating your Field Type as a Service" section and call `array_flip` as I think it is clearer to keep the keys as keys (!) for parameters, especially as the labels could contain some spaces. Commits ------- 74b662b Fix choice keys and values for custom field types
2 parents 814e5bd + 74b662b commit a216951

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

form/create_custom_field_type.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extend
3232
{
3333
$resolver->setDefaults(array(
3434
'choices' => array(
35-
'standard' => 'Standard Shipping',
36-
'expedited' => 'Expedited Shipping',
37-
'priority' => 'Priority Shipping',
35+
'Standard Shipping' => 'standard',
36+
'Expedited Shipping' => 'expedited',
37+
'Priority Shipping' => 'priority',
3838
)
3939
));
4040
}
@@ -394,7 +394,7 @@ method to ``ShippingType``, which receives the shipping configuration::
394394
public function configureOptions(OptionsResolver $resolver)
395395
{
396396
$resolver->setDefaults(array(
397-
'choices' => $this->shippingOptions,
397+
'choices' => array_flip($this->shippingOptions),
398398
));
399399
}
400400

0 commit comments

Comments
 (0)