From 1c74898723121d671c6f8f5cb93644cc56af722e Mon Sep 17 00:00:00 2001 From: ureimers Date: Tue, 17 Dec 2013 18:18:11 +0100 Subject: [PATCH 1/5] Update UPGRADE-2.3.md --- UPGRADE-2.3.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 26fbc1e6771e3..1ecfe753cc0a4 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -169,6 +169,45 @@ Form $builder->add('field', 'text'); $form = $builder->getForm(); ``` + + * Even if it wasn't intended, it was possible to set a form type's `data` + option to `null` if you wanted the form component to set the form's data + to the data of the object bound to the form (if one was bound). + This was used in some projects to preset a form field with optional + initial data as long as there wasn't already data set through a bound object. + Altough this feature is intended, setting the `data` option for a form + by default also locks that form's data so that it can't be overriden by + a later bound object. To disable said lock you have to specifically call + `FormConfigBuilderInterface:setDataLocked()`: + + Before: + + ``` + $builder->add('field', 'text', array( + 'data' => $options['default_data'] ?: null, + )); + ``` + + After: + + ``` + $builder->add('field', 'text', array( + 'data' => $options['default_data'] ?: null, + )); + $builder->get('field')->setDataLocked(false); + ``` + + The cleanest solution would be to only set the `data` option if there's + actually data so pre-set. + + After (Alternative 1): + + ``` + $fieldOptions = array(); + if ($options['default_data']) { + $fieldOptions['data'] = $options['default_data']; + } + $builder->add('field', 'text', $fieldOptions); PropertyAccess -------------- @@ -254,7 +293,7 @@ Console Before: - ``` + ```a if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { ... } ``` From ce541127103eafd908487b937458b6dad8b73a22 Mon Sep 17 00:00:00 2001 From: ureimers Date: Tue, 17 Dec 2013 18:28:27 +0100 Subject: [PATCH 2/5] Fixed typo and additional character --- UPGRADE-2.3.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 1ecfe753cc0a4..826a0bac3385d 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -173,7 +173,7 @@ Form * Even if it wasn't intended, it was possible to set a form type's `data` option to `null` if you wanted the form component to set the form's data to the data of the object bound to the form (if one was bound). - This was used in some projects to preset a form field with optional + This was used in some projects to pre-set a form field with optional initial data as long as there wasn't already data set through a bound object. Altough this feature is intended, setting the `data` option for a form by default also locks that form's data so that it can't be overriden by @@ -198,7 +198,7 @@ Form ``` The cleanest solution would be to only set the `data` option if there's - actually data so pre-set. + actually data to pre-set. After (Alternative 1): @@ -293,7 +293,7 @@ Console Before: - ```a + ``` if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { ... } ``` From 32340a0d43bd29fe7173bf37774e14f392155b85 Mon Sep 17 00:00:00 2001 From: ureimers Date: Tue, 17 Dec 2013 18:51:24 +0100 Subject: [PATCH 3/5] Added missing escape ending ("```") to code block Although the output was fine the .md file wasn't. --- UPGRADE-2.3.md | 1 + 1 file changed, 1 insertion(+) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 826a0bac3385d..707e36120f15a 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -208,6 +208,7 @@ Form $fieldOptions['data'] = $options['default_data']; } $builder->add('field', 'text', $fieldOptions); + ``` PropertyAccess -------------- From b591d52e359da758f153f0bbde867fe7d48f1360 Mon Sep 17 00:00:00 2001 From: ureimers Date: Wed, 18 Dec 2013 10:34:08 +0100 Subject: [PATCH 4/5] Updated wording and removed alternative The fact that not setting the `data` option doesn't lock the form can be taken out of the description which states that *if* the `data` option is set the data will be locked automatically (so the opposite must be happening if it isn't). --- UPGRADE-2.3.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 707e36120f15a..5f3062ba0f8e1 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -170,7 +170,7 @@ Form $form = $builder->getForm(); ``` - * Even if it wasn't intended, it was possible to set a form type's `data` + * While it wasn't intended, it was possible to set a form type's `data` option to `null` if you wanted the form component to set the form's data to the data of the object bound to the form (if one was bound). This was used in some projects to pre-set a form field with optional @@ -196,19 +196,6 @@ Form )); $builder->get('field')->setDataLocked(false); ``` - - The cleanest solution would be to only set the `data` option if there's - actually data to pre-set. - - After (Alternative 1): - - ``` - $fieldOptions = array(); - if ($options['default_data']) { - $fieldOptions['data'] = $options['default_data']; - } - $builder->add('field', 'text', $fieldOptions); - ``` PropertyAccess -------------- From 7e523d7725e6e5727ef38a7ac077368eca2aea43 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 28 Dec 2013 20:29:19 +0100 Subject: [PATCH 5/5] [Form] Fixed wording in the UPGRADE file --- UPGRADE-2.3.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index 5f3062ba0f8e1..0b64a58a86264 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -169,32 +169,31 @@ Form $builder->add('field', 'text'); $form = $builder->getForm(); ``` - - * While it wasn't intended, it was possible to set a form type's `data` - option to `null` if you wanted the form component to set the form's data - to the data of the object bound to the form (if one was bound). - This was used in some projects to pre-set a form field with optional - initial data as long as there wasn't already data set through a bound object. - Altough this feature is intended, setting the `data` option for a form - by default also locks that form's data so that it can't be overriden by - a later bound object. To disable said lock you have to specifically call - `FormConfigBuilderInterface:setDataLocked()`: + + * Previously, when the "data" option of a field was set to `null` and the + containing form was mapped to an object, the field would receive the data + from the object as default value. This functionality was unintended and fixed + to use `null` as default value in Symfony 2.3. + + In cases where you made use of the previous behavior, you should now remove + the "data" option altogether. Before: ``` $builder->add('field', 'text', array( - 'data' => $options['default_data'] ?: null, + 'data' => $defaultData ?: null, )); ``` - + After: ``` - $builder->add('field', 'text', array( - 'data' => $options['default_data'] ?: null, - )); - $builder->get('field')->setDataLocked(false); + $options = array(); + if ($defaultData) { + $options['data'] = $defaultData; + } + $builder->add('field', 'text', $options); ``` PropertyAccess