From 7e8490715c29e02270cee788f09a2b0e43496a5e Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 6 Nov 2016 15:11:25 +0100 Subject: [PATCH] [Form] fixed "empty_value" option deprecation --- .../Component/Form/Extension/Core/Type/ChoiceType.php | 9 +++++++-- .../Component/Form/Extension/Core/Type/DateType.php | 4 ++-- .../Component/Form/Extension/Core/Type/TimeType.php | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 49bea1acec..d376109828 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -39,6 +39,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class ChoiceType extends AbstractType { + /** + * @internal To be removed in 3.0 + */ + const DEPRECATED_EMPTY_VALUE = '__deprecated_empty_value__'; + /** * Caches created choice lists. * @@ -336,7 +341,7 @@ class ChoiceType extends AbstractType }; $placeholderNormalizer = function (Options $options, $placeholder) use ($that) { - if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) { + if ($that::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) { @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); if (null === $placeholder || '' === $placeholder) { @@ -388,7 +393,7 @@ class ChoiceType extends AbstractType 'preferred_choices' => array(), 'group_by' => null, 'empty_data' => $emptyData, - 'empty_value' => new \Exception(), // deprecated + 'empty_value' => self::DEPRECATED_EMPTY_VALUE, 'placeholder' => $placeholder, 'error_bubbling' => false, 'compound' => $compound, diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index ae4c6bacf2..8af7a96f13 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -183,7 +183,7 @@ class DateType extends AbstractType }; $placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) { - if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) { + if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) { @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); $placeholder = $options['empty_value']; @@ -218,7 +218,7 @@ class DateType extends AbstractType 'format' => $format, 'model_timezone' => null, 'view_timezone' => null, - 'empty_value' => new \Exception(), // deprecated + 'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE, 'placeholder' => $placeholder, 'html5' => true, // Don't modify \DateTime classes by reference, we treat diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index 8232170278..dab0572927 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -171,7 +171,7 @@ class TimeType extends AbstractType }; $placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) { - if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) { + if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) { @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); $placeholder = $options['empty_value']; @@ -203,7 +203,7 @@ class TimeType extends AbstractType 'with_seconds' => false, 'model_timezone' => null, 'view_timezone' => null, - 'empty_value' => new \Exception(), // deprecated + 'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE, 'placeholder' => $placeholder, 'html5' => true, // Don't modify \DateTime classes by reference, we treat