8000 [Form] fixed "empty_value" option deprecation · symfony/symfony@7e84907 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e84907

Browse files
committed
[Form] fixed "empty_value" option deprecation
1 parent f37ac13 commit 7e84907

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
class ChoiceType extends AbstractType
4141
{
42+
/**
43+
* @internal To be removed in 3.0
44+
*/
45+
const DEPRECATED_EMPTY_VALUE = '__deprecated_empty_value__';
46+
4247
/**
4348
* Caches created choice lists.
4449
*
@@ -336,7 +341,7 @@ public function configureOptions(OptionsResolver $resolver)
336341
};
337342

338343
$placeholderNormalizer = function (Options $options, $placeholder) use ($that) {
339-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
344+
if ($that::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
340345
@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);
341346

342347
if (null === $placeholder || '' === $placeholder) {
@@ -388,7 +393,7 @@ public function configureOptions(OptionsResolver $resolver)
388393
'preferred_choices' => array(),
389394
'group_by' => null,
390395
'empty_data' => $emptyData,
391-
'empty_value' => new \Exception(), // deprecated
396+
'empty_value' => self::DEPRECATED_EMPTY_VALUE,
392397
'placeholder' => $placeholder,
393398
'error_bubbling' => false,
394399
'compound' => $compound,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function configureOptions(OptionsResolver $resolver)
183183
};
184184

185185
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
186-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
186+
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
187187
@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);
188188

189189
$placeholder = $options['empty_value'];
@@ -218,7 +218,7 @@ public function configureOptions(OptionsResolver $resolver)
218218
'format' => $format,
219219
'model_timezone' => null,
220220
'view_timezone' => null,
221-
'empty_value' => new \Exception(), // deprecated
221+
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
222222
'placeholder' => $placeholder,
223223
'html5' => true,
224224
// Don't modify \DateTime classes by reference, we treat

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function configureOptions(OptionsResolver $resolver)
171171
};
172172

173173
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
174-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
174+
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
175175
@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);
176176

177177
$placeholder = $options['empty_value'];
@@ -203,7 +203,7 @@ public function configureOptions(OptionsResolver $resolver)
203203
'with_seconds' => false,
204204
'model_timezone' => null,
205205
'view_timezone' => null,
206-
'empty_value' => new \Exception(), // deprecated
206+
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
207207
'placeholder' => $placeholder,
208208
'html5' => true,
209209
// Don't modify \DateTime classes by reference, we treat

0 commit comments

Comments
 (0)
0