E609 [Form] fixed "empty_value" option deprecation by HeahDude · Pull Request #20425 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
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.
10BC0
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

class ChoiceType extends AbstractType
{
/**
* @internal To be removed in 3.0
*/
const DEPRECATED_EMPTY_VALUE = '__deprecated_empty_value__';
Copy link
Member

Choose a reason for hiding this comment

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

@internal then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas done :)


/**
* Caches created choice lists.
*
Expand Down Expand Up @@ -336,7 +341,7 @@ public function configureOptions(OptionsResolver $resolver)
};

$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) {
Expand Down Expand Up @@ -388,7 +393,7 @@ public function configureOptions(OptionsResolver $resolver)
'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,
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function configureOptions(OptionsResolver $resolver)
};

$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'];
Expand Down Expand Up @@ -218,7 +218,7 @@ public function configureOptions(OptionsResolver $resolver)
'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
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function configureOptions(OptionsResolver $resolver)
};

$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'];
Expand Down Expand Up @@ -203,7 +203,7 @@ public function configureOptions(OptionsResolver $resolver)
'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
Expand Down
0