8000 trigger deprecation warning when using empty_value · symfony/symfony@8e215f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e215f2

Browse files
committed
trigger deprecation warning when using empty_value
The `empty_value` option is deprecated in the `choice`, `date`, and `time` form types. Therefore, a deprecation warning must be triggered when the users configures a value for this option. The `datetime` form type does not need to be updated as it passes configured values to the `date` and `time` form types which trigger deprecation warnings anyway.
1 parent ea2bd2a commit 8e215f2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ public function configureOptions(OptionsResolver $resolver)
253253
};
254254

255255
// for BC with the "empty_value" option
256-
$placeholder = function (Options $options) {
256+
$placeholder = function (Options $options) use ($emptyValue) {
257+
if ($emptyValue !== $options['empty_value']) {
258+
@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);
259+
}
260+
257261
return $options['empty_value'];
258262
};
259263

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public function configureOptions(OptionsResolver $resolver)
179179
return $options['required'] ? null : '';
180180
};
181181

182-
$placeholder = function (Options $options) {
182+
$placeholder = function (Options $options) use ($emptyValue) {
183+
if ($emptyValue !== $options['empty_value']) {
184+
@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);
185+
}
186+
183187
return $options['empty_value'];
184188
};
185189

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ public function configureOptions(OptionsResolver $resolver)
168168
};
169169

170170
// for BC with the "empty_value" option
171-
$placeholder = function (Options $options) {
171+
$placeholder = function (Options $options) use ($emptyValue) {
172+
if ($emptyValue !== $options['empty_value']) {
173+
@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);
174+
}
175+
172176
return $options['empty_value'];
173177
};
174178

0 commit comments

Comments
 (0)
0