8000 minor #32183 [Form] Removed legacy code from NumberType (yceruto) · symfony/symfony@c10ad18 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c10ad18

Browse files
committed
minor #32183 [Form] Removed legacy code from NumberType (yceruto)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Form] Removed legacy code from NumberType | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Ref: #32130 Commits ------- 148ba1f Removed legacy code from NumberType
2 parents 01c0960 + 148ba1f commit c10ad18

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHANGELOG
1717
* removed the `$scale` argument of the `IntegerToLocalizedStringTransformer`
1818
* removed `TemplatingExtension` and `TemplatingRendererEngine` classes, use Twig instead
1919
* passing a null message when instantiating a `Symfony\Component\Form\FormError` is not allowed
20+
* removed support for using `int` or `float` as data for the `NumberType` when the `input` option is set to `string`
2021

2122
4.4.0
2223
-----

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15-
use Symfony\Component\Form\CallbackTransformer;
1615
use Symfony\Component\Form\Exception\LogicException;
1716
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
1817
use Symfony\Component\Form\Extension\Core\DataTransformer\StringToFloatTransformer;
@@ -38,19 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
3837

3938
if ('string' === $options['input']) {
4039
$builder->addModelTransformer(new StringToFloatTransformer($options['scale']));
41-
$builder->addModelTransformer(new CallbackTransformer(
42-
function ($value) {
43-
if (\is_float($value) || \is_int($value)) {
44-
@trigger_error(sprintf('Using the %s with float or int data when the "input" option is set to "string" is deprecated since Symfony 4.4 and will throw an exception in 5.0.', self::class), E_USER_DEPRECATED);
45-
$value = (string) $value;
46-
}
47-
48-
return $value;
49-
},
50-
function ($value) {
51-
return $value;
52-
}
53-
));
5440
}
5541
}
5642

src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,27 @@ public function testDefaultFormattingWithScaleAndStringInput(): void
7878
}
7979

8080
/**
81-
* @group legacy
82-
* @expectedDeprecation Using the Symfony\Component\Form\Extension\Core\Type\NumberType with float or int data when the "input" option is set to "string" is deprecated since Symfony 4.4 and will throw an exception in 5.0.
81+
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
82+
* @expectedExceptionMessage Expected a numeric string.
8383
*/
8484
public function testStringInputWithFloatData(): void
8585
{
86-
$form = $this->factory->create(static::TESTED_TYPE, 12345.6789, [
86+
$this->factory->create(static::TESTED_TYPE, 12345.6789, [
8787
'input' => 'string',
8888
'scale' => 2,
8989
]);
90-
91-
$this->assertSame('12345,68', $form->createView()->vars['value']);
9290
}
9391

9492
/**
95-
* @group legacy
96-
* @expectedDeprecation Using the Symfony\Component\Form\Extension\Core\Type\NumberType with float or int data when the "input" option is set to "string" is deprecated since Symfony 4.4 and will throw an exception in 5.0.
93+
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
94+
* @expectedExceptionMessage Expected a numeric string.
9795
*/
9896
public function testStringInputWithIntData(): void
9997
{
100-
$form = $this->factory->create(static::TESTED_TYPE, 12345, [
98+
$this->factory->create(static::TESTED_TYPE, 12345, [
10199
'input' => 'string',
102100
'scale' => 2,
103101
]);
104-
105-
$this->assertSame('12345,00', $form->createView()->vars['value']);
106102
}
107103

108104
public function testDefaultFormattingWithRounding(): void

0 commit comments

Comments
 (0)
0