8000 [Form] trigger deprecation warning when using empty_value by xabbuh · Pull Request #15945 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] trigger deprecation warning when using empty_value #15945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,8 @@ public function configureOptions(OptionsResolver $resolver)
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) {
Expand Down Expand Up @@ -287,6 +282,12 @@ public function configureOptions(OptionsResolver $resolver)
};

$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;
Expand Down Expand Up @@ -328,7 +329,7 @@ public function configureOptions(OptionsResolver $resolver)
'preferred_choices' => array(),
'group_by' => null,
'empty_data' => $emptyData,
'empty_value' => $emptyValue, // deprecated
'empty_value' => new \Exception(), // deprecated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really nice, but as the empty value can be nearly everthing it was best I could think of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite unfortunate choice, as exceptions include stacktrace, which can cause circular references if used in functional tests. My Behat test suite with new \Exception() uses 200MB of memory, but with null it only uses 103MB. Can we use some other object instead? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #20425

'placeholder' => $placeholder,
'error_bubbling' => false,
'compound' => $compound,
Expand All @@ -340,7 +341,6 @@ public function configureOptions(OptionsResolver $resolver)
));

$resolver->setNormalizer('choice_list', $choiceListNormalizer);
$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);

Expand Down
15 changes: 8 additions & 7 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,17 @@ public function configureOptions(OptionsResolver $resolver)
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);

Expand Down Expand Up @@ -213,7 +215,7 @@ public function configureOptions(OptionsResolver $resolver)
'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
Expand All @@ -228,7 +230,6 @@ public function configureOptions(OptionsResolver $resolver)
'compound' => $compound,
));

$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

$resolver->setAllowedValues('input', array(
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,17 @@ public function configureOptions(OptionsResolver $resolver)
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);

Expand All @@ -199,7 +200,7 @@ public function configureOptions(OptionsResolver $resolver)
'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
Expand All @@ -214,7 +215,6 @@ public function configureOptions(OptionsResolver $resolver)
'compound' => $compound,
));

$resolver->setNormalizer('empty_value', $placeholderNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

$resolver->setAllowedValues('input', array(
Expand Down
0