8000 minor #20425 [Form] fixed "empty_value" option deprecation (HeahDude) · src-run/symfony@fe15381 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe15381

Browse files
committed
minor symfony#20425 [Form] fixed "empty_value" option deprecation (HeahDude)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] fixed "empty_value" option deprecation | Q | A | ------------- | --- | Branch? | 2.x only | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#15945 (comment) | License | MIT | Doc PR | ~ I didn't make any profiling but a resolver instance is passed to `configureOptions()` creating locale variables including those exceptions for each field using one of the patched form types, so I guess the memory usage can grow really fast. Commits ------- 7e84907 [Form] fixed "empty_value" option deprecation
2 parents 5f62f01 + 7e84907 commit fe15381

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
class ChoiceType extends AbstractType
4141
{
42+
/**
43+
* @internal To be removed in 3.0
44+
*/
45+
const DEPRECATED_EMPTY_VALUE = '__deprecated_empty_value__';
46+
4247
/**
4348
* Caches created choice lists.
4449
*
@@ -336,7 +341,7 @@ public function configureOptions(OptionsResolver $resolver)
336341
};
337342

338343
$placeholderNormalizer = function (Options $options, $placeholder) use ($that) {
339-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
344+
if ($that::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
340345
@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);
341346

342347
if (null === $placeholder || '' === $placeholder) {
@@ -388,7 +393,7 @@ public function configureOptions(OptionsResolver $resolver)
388393
'preferred_choices' => array(),
389394
'group_by' => null,
390395
'empty_data' => $emptyData,
391-
'empty_value' => new \Exception(), // deprecated
396+
'empty_value' => self::DEPRECATED_EMPTY_VALUE,
392397
'placeholder' => $placeholder,
393398
'error_bubbling' => false,
394399
'compound' => $compound,

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function configureOptions(OptionsResolver $resolver)
183183
};
184184

185185
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
186-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
186+
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
187187
@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);
188188

189189
$placeholder = $options['empty_value'];
@@ -218,7 +218,7 @@ public function configureOptions(OptionsResolver $resolver)
218218
'format' => $format,
219219
'model_timezone' => null,
220220
'view_timezone' => null,
221-
'empty_value' => new \Exception(), // deprecated
221+
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
222222
'placeholder' => $placeholder,
223223
'html5' => true,
224224
// Don't modify \DateTime classes by reference, we treat

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function configureOptions(OptionsResolver $resolver)
184184
};
185185

186186
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
187-
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
187+
if (ChoiceType::DEPRECATED_EMPTY_VALUE !== $options['empty_value']) {
188188
@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);
189189

190190
$placeholder = $options['empty_value'];
@@ -216,7 +216,7 @@ public function configureOptions(OptionsResolver $resolver)
216216
'with_seconds' => false,
217217
'model_timezone' => null,
218218
'view_timezone' => null,
219-
'empty_value' => new \Exception(), // deprecated
219+
'empty_value' => ChoiceType::DEPRECATED_EMPTY_VALUE,
220220
'placeholder' => $placeholder,
221221
'html5' => true,
222222
// Don't modify \DateTime classes by reference, we treat

0 commit comments

Comments
 (0)
0