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
bug #16886 [Form] [ChoiceType] Prefer placeholder to empty_value (boite)
This PR was squashed before being merged into the 2.7 branch (closes #16886).
Discussion
----------
[Form] [ChoiceType] Prefer placeholder to empty_value
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #16885
| License | MIT
| Doc PR | -
Prefer an explicitly set `placeholder` option (i.e. `false` or a non-empty
string) to an `empty_value` option when both are set.
The fix is to change the behaviour in the placeholder normalizer in
ChoiceType::configureOptions so that the value of the `empty_value` option is
used for placeholder only when the value of `placeholder` is null or an empty
string.
Commits
-------
a4d4c8a [Form] [ChoiceType] Prefer placeholder to empty_value
Copy file name to clipboardExpand all lines: Extension/Core/Type/ChoiceType.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -345,7 +345,9 @@ public function configureOptions(OptionsResolver $resolver)
345
345
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
346
346
@trigger_error(sprintf('The form option "empty_value" of the "%s" form type (%s) is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', $that->getName(), __CLASS__), E_USER_DEPRECATED);
347
347
348
-
$placeholder = $options['empty_value'];
348
+
if (null === $placeholder || '' === $placeholder) {
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, false, null),
1922
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, null, null),
1923
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, '', null),
1924
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, 'bar', null),
1925
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, false, null, false, null),
1926
+
'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, ''),
1927
+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, '', ''),
1928
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, 'bar', 'bar'),
1929
+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, false, false, '', false, null),
1930
+
'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),
1931
+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, false, '', '', ''),
1932
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, false, '', 'bar', 'bar'),
1933
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, false, 'foo', false, 'foo'),
1934
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, false, 'foo', null, 'foo'),
1935
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, false, 'foo', '', 'foo'),
1936
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, false, 'foo', 'bar', 'foo'),
1937
+
// single non-expanded, required
1938
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, false, null),
1939
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, null, null),
1940
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, '', null),
1941
+
'A placeholder is not used if it is explicitly set to false' => array(false, false, true, false, 'bar', null),
1942
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, true, null, false, null),
1943
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, null, null, null),
1944
+
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, '', ''),
1945
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, true, null, 'bar', 'bar'),
1946
+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, false, true, '', false, null),
1947
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, false, true, '', null, null),
1948
+
'An empty string empty_value is used if placeholder is also an empty string [maintains BC]' => array(false, false, true, '', '', ''),
1949
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, false, true, '', 'bar', 'bar'),
1950
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, false, true, 'foo', false, 'foo'),
1951
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, false, true, 'foo', null, 'foo'),
1952
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, false, true, 'foo', '', 'foo'),
1953
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, false, true, 'foo', 'bar', 'foo'),
1954
+
// single expanded, not required
1955
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, false, null),
1956
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, null, null),
1957
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, '', null),
1958
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, false, false, 'bar', null),
1959
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, false, null, false, null),
1960
+
'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),
1961
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, null, '', 'None'),
1962
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, false, null, 'bar', 'bar'),
1963
+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, true, false, '', false, null),
1964
+
'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),
1965
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, false, '', '', 'None'),
1966
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, false, '', 'bar', 'bar'),
1967
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, false, 'foo', false, 'foo'),
1968
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, false, 'foo', null, 'foo'),
1969
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, false, 'foo', '', 'foo'),
1970
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, false, 'foo', 'bar', 'foo'),
1971
+
// single expanded, required
1972
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, false, null),
1973
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, null, null),
1974
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, '', null),
1975
+
'A placeholder is not used if it is explicitly set to false' => array(false, true, true, false, 'bar', null),
1976
+
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, true, true, null, false, null),
1977
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, null, null, null),
1978
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, null, '', 'None'),
1979
+
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, true, true, null, 'bar', 'bar'),
1980
+
'A placeholder is not used if it is an empty string and empty_value is set to false [maintains BC]' => array(false, true, true, '', false, null),
1981
+
'A placeholder is not used if empty_value is not set [maintains BC]' => array(false, true, true, '', null, null),
1982
+
'An empty string empty_value is converted to "None" in an expanded single choice field [maintains BC]' => array(false, true, true, '', '', 'None'),
1983
+
'A non-empty string empty_value is used if placeholder is an empty string [maintains BC]' => array(false, true, true, '', 'bar', 'bar'),
1984
+
'A non-empty string placeholder takes precedence over an empty_value set to false' => array(false, true, true, 'foo', false, 'foo'),
1985
+
'A non-empty string placeholder takes precendece over a not set empty_value' => array(false, true, true, 'foo', null, 'foo'),
1986
+
'A non-empty string placeholder takes precedence over an empty string empty_value' => array(false, true, true, 'foo', '', 'foo'),
1987
+
'A non-empty string placeholder takes precedence over a non-empty string empty_value' => array(false, true, true, 'foo', 'bar', 'foo'),
0 commit comments