You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an extra condition to the use of the value of the empty_value option
as the placeholder: the value of the placeholder option must be null or
an empty string (i.e. not explicitly set).
Test the effects of setting both placeholder and empty_value.
Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -325,7 +325,9 @@ public function configureOptions(OptionsResolver $resolver)
325
325
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
326
326
@trigger_error('The form option "empty_value" is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', E_USER_DEPRECATED);
327
327
328
-
$placeholder = $options['empty_value'];
328
+
if (null === $placeholder || '' === $placeholder) {
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, false, null),
1760
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, null, null),
1761
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, '', null),
1762
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, 'bar', null),
1763
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, false, null, false, null),
1764
+
'An unset empty_value is automaticaly made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, false, false, null, null, ''),
1765
+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, '', ''),
1766
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, 'bar', 'bar'),
1767
+
'A placeholder is not used if it is an empty string and empty_value is set to false [mainatins BC]' => array(false, false, false, '', false, null),
1768
+
'An unset empty_value is automatically made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, false, false, '', null, null),
1769
+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, false, '', '', ''),
1770
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, false, '', 'bar', 'bar'),
1771
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, false, 'foo', false, 'foo'),
1772
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, false, 'foo', null, 'foo'),
1773
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, false, 'foo', '', 'foo'),
1774
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, false, 'foo', 'bar', 'foo'),
1775
+
// single non-expanded, required
1776
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, false, null),
1777
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, null, null),
1778
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, '', null),
1779
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, 'bar', null),
1780
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, true, null, false, null),
1781
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, null, null, null),
1782
+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, '', ''),
1783
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, 'bar', 'bar'),
1784
+
'A placeholder is not used if it is an empty string and empty_value is set to false [mainatins BC]' => array(false, false, true, '', false, null),
1785
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, '', null, null),
1786
+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, true, '', '', ''),
1787
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, true, '', 'bar', 'bar'),
1788
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, true, 'foo', false, 'foo'),
1789
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, true, 'foo', null, 'foo'),
1790
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, true, 'foo', '', 'foo'),
1791
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, true, 'foo', 'bar', 'foo'),
1792
+
// single expanded, not required
1793
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, false, null),
1794
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, null, null),
1795
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, '', null),
1796
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, 'bar', null),
1797
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, false, null, false, null),
1798
+
'An unset empty_value is automaticaly made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, true, false, null, null, null),
1799
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, null, '', 'None'),
1800
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, false, null, 'bar', 'bar'),
1801
+
'A placeholder is not used if it is an empty string and empty_value is set to false [mainatins BC]' => array(false, true, false, '', false, null),
1802
+
'An unset empty_value is automatically made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, true, false, '', null, null),
1803
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, '', '', 'None'),
1804
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, false, '', 'bar', 'bar'),
1805
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, false, 'foo', false, 'foo'),
1806
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, false, 'foo', null, 'foo'),
1807
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, false, 'foo', '', 'foo'),
1808
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, false, 'foo', 'bar', 'foo'),
1809
+
// single expanded, required
1810
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, false, null),
1811
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, null, null),
1812
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, '', null),
1813
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, 'bar', null),
1814
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, true, null, false, null),
1815
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, null, null, null),
1816
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, null, '', 'None'),
1817
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, true, null, 'bar', 'bar'),
1818
+
'A placeholder is not used if it is an empty string and empty_value is set to false [mainatins BC]' => array(false, true, true, '', false, null),
1819
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, '', null, null),
1820
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, '', '', 'None'),
1821
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, true, '', 'bar', 'bar'),
1822
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, true, 'foo', false, 'foo'),
1823
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, true, 'foo', null, 'foo'),
1824
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, true, 'foo', '', 'foo'),
1825
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, true, 'foo', 'bar', 'foo'),
0 commit comments