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:
parent
399b1d5cb0
commit
405d4a8ead
@ -248,13 +248,8 @@ class ChoiceType extends AbstractType
|
|||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$emptyValue = function (Options $options) {
|
|
||||||
return $options['required'] ? null : '';
|
|
||||||
};
|
|
||||||
|
|
||||||
// for BC with the "empty_value" option
|
|
||||||
$placeholder = function (Options $options) {
|
$placeholder = function (Options $options) {
|
||||||
return $options['empty_value'];
|
return $options['required'] ? null : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
|
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
|
||||||
@ -287,6 +282,12 @@ class ChoiceType extends AbstractType
|
|||||||
};
|
};
|
||||||
|
|
||||||
$placeholderNormalizer = function (Options $options, $placeholder) {
|
$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']) {
|
if ($options['multiple']) {
|
||||||
// never use an empty value for this case
|
// never use an empty value for this case
|
||||||
return;
|
return;
|
||||||
@ -328,7 +329,7 @@ class ChoiceType extends AbstractType
|
|||||||
'preferred_choices' => array(),
|
'preferred_choices' => array(),
|
||||||
'group_by' => null,
|
'group_by' => null,
|
||||||
'empty_data' => $emptyData,
|
'empty_data' => $emptyData,
|
||||||
'empty_value' => $emptyValue, // deprecated
|
'empty_value' => new \Exception(), // deprecated
|
||||||
'placeholder' => $placeholder,
|
'placeholder' => $placeholder,
|
||||||
'error_bubbling' => false,
|
'error_bubbling' => false,
|
||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
@ -340,7 +341,6 @@ class ChoiceType extends AbstractType
|
|||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('choice_list', $choiceListNormalizer);
|
$resolver->setNormalizer('choice_list', $choiceListNormalizer);
|
||||||
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
|
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
|
||||||
|
|
||||||
|
@ -175,15 +175,17 @@ class DateType extends AbstractType
|
|||||||
return $options['widget'] !== 'single_text';
|
return $options['widget'] !== 'single_text';
|
||||||
};
|
};
|
||||||
|
|
||||||
$emptyValue = $placeholderDefault = function (Options $options) {
|
$placeholder = $placeholderDefault = function (Options $options) {
|
||||||
return $options['required'] ? null : '';
|
return $options['required'] ? null : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$placeholder = function (Options $options) {
|
|
||||||
return $options['empty_value'];
|
|
||||||
};
|
|
||||||
|
|
||||||
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
|
$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)) {
|
if (is_array($placeholder)) {
|
||||||
$default = $placeholderDefault($options);
|
$default = $placeholderDefault($options);
|
||||||
|
|
||||||
@ -213,7 +215,7 @@ class DateType extends AbstractType
|
|||||||
'format' => $format,
|
'format' => $format,
|
||||||
'model_timezone' => null,
|
'model_timezone' => null,
|
||||||
'view_timezone' => null,
|
'view_timezone' => null,
|
||||||
'empty_value' => $emptyValue, // deprecated
|
'empty_value' => new \Exception(), // deprecated
|
||||||
'placeholder' => $placeholder,
|
'placeholder' => $placeholder,
|
||||||
'html5' => true,
|
'html5' => true,
|
||||||
// Don't modify \DateTime classes by reference, we treat
|
// Don't modify \DateTime classes by reference, we treat
|
||||||
@ -228,7 +230,6 @@ class DateType extends AbstractType
|
|||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
|
|
||||||
$resolver->setAllowedValues('input', array(
|
$resolver->setAllowedValues('input', array(
|
||||||
|
@ -163,16 +163,17 @@ class TimeType extends AbstractType
|
|||||||
return $options['widget'] !== 'single_text';
|
return $options['widget'] !== 'single_text';
|
||||||
};
|
};
|
||||||
|
|
||||||
$emptyValue = $placeholderDefault = function (Options $options) {
|
$placeholder = $placeholderDefault = function (Options $options) {
|
||||||
return $options['required'] ? null : '';
|
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) {
|
$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)) {
|
if (is_array($placeholder)) {
|
||||||
$default = $placeholderDefault($options);
|
$default = $placeholderDefault($options);
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ class TimeType extends AbstractType
|
|||||||
'with_seconds' => false,
|
'with_seconds' => false,
|
||||||
'model_timezone' => null,
|
'model_timezone' => null,
|
||||||
'view_timezone' => null,
|
'view_timezone' => null,
|
||||||
'empty_value' => $emptyValue, // deprecated
|
'empty_value' => new \Exception(), // deprecated
|
||||||
'placeholder' => $placeholder,
|
'placeholder' => $placeholder,
|
||||||
'html5' => true,
|
'html5' => true,
|
||||||
// Don't modify \DateTime classes by reference, we treat
|
// Don't modify \DateTime classes by reference, we treat
|
||||||
@ -214,7 +215,6 @@ class TimeType extends AbstractType
|
|||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
|
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
|
|
||||||
$resolver->setAllowedValues('input', array(
|
$resolver->setAllowedValues('input', array(
|
||||||
|
Reference in New Issue
Block a user