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.
This commit is contained in:
Christian Flothmann 2015-09-27 17:20:43 +02:00
parent 399b1d5cb0
commit 405d4a8ead
3 changed files with 24 additions and 23 deletions

View File

@ -248,13 +248,8 @@ class ChoiceType extends AbstractType
return '';
};
$emptyValue = function (Options $options) {
return $options['required'] ? null : '';
};
// for BC with the "empty_value" option
$placeholder = function (Options $options) {
return $options['empty_value'];
return $options['required'] ? null : '';
};
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
@ -287,6 +282,12 @@ class ChoiceType extends AbstractType
};
$placeholderNormalizer = function (Options $options, $placeholder) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
@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'];
}
if ($options['multiple']) {
// never use an empty value for this case
return;
@ -328,7 +329,7 @@ class ChoiceType extends AbstractType
'preferred_choices' => array(),
'group_by' => null,
'empty_data' => $emptyData,
'empty_value' => $emptyValue, // deprecated
'empty_value' => new \Exception(), // deprecated
'placeholder' => $placeholder,
'error_bubbling' => false,
'compound' => $compound,
@ -340,7 +341,6 @@ class ChoiceType extends AbstractType
));
$resolver->setNormalizer('choice_list', $choiceListNormalizer);
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);

View File

@ -175,15 +175,17 @@ class DateType extends AbstractType
return $options['widget'] !== 'single_text';
};
$emptyValue = $placeholderDefault = function (Options $options) {
$placeholder = $placeholderDefault = function (Options $options) {
return $options['required'] ? null : '';
};
$placeholder = function (Options $options) {
return $options['empty_value'];
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
@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'];
}
if (is_array($placeholder)) {
$default = $placeholderDefault($options);
@ -213,7 +215,7 @@ class DateType extends AbstractType
'format' => $format,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => $emptyValue, // deprecated
'empty_value' => new \Exception(), // deprecated
'placeholder' => $placeholder,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat
@ -228,7 +230,6 @@ class DateType extends AbstractType
'compound' => $compound,
));
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setAllowedValues('input', array(

View File

@ -163,16 +163,17 @@ class TimeType extends AbstractType
return $options['widget'] !== 'single_text';
};
$emptyValue = $placeholderDefault = function (Options $options) {
$placeholder = $placeholderDefault = function (Options $options) {
return $options['required'] ? null : '';
};
// for BC with the "empty_value" option
$placeholder = function (Options $options) {
return $options['empty_value'];
};
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
@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'];
}
if (is_array($placeholder)) {
$default = $placeholderDefault($options);
@ -199,7 +200,7 @@ class TimeType extends AbstractType
'with_seconds' => false,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => $emptyValue, // deprecated
'empty_value' => new \Exception(), // deprecated
'placeholder' => $placeholder,
'html5' => true,
// Don't modify \DateTime classes by reference, we treat
@ -214,7 +215,6 @@ class TimeType extends AbstractType
'compound' => $compound,
));
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setAllowedValues('input', array(