Removed legacy code from NumberType
This commit is contained in:
parent
0c90809ebd
commit
148ba1feeb
@ -17,6 +17,7 @@ CHANGELOG
|
|||||||
* removed the `$scale` argument of the `IntegerToLocalizedStringTransformer`
|
* removed the `$scale` argument of the `IntegerToLocalizedStringTransformer`
|
||||||
* removed `TemplatingExtension` and `TemplatingRendererEngine` classes, use Twig instead
|
* removed `TemplatingExtension` and `TemplatingRendererEngine` classes, use Twig instead
|
||||||
* passing a null message when instantiating a `Symfony\Component\Form\FormError` is not allowed
|
* passing a null message when instantiating a `Symfony\Component\Form\FormError` is not allowed
|
||||||
|
* removed support for using `int` or `float` as data for the `NumberType` when the `input` option is set to `string`
|
||||||
|
|
||||||
4.4.0
|
4.4.0
|
||||||
-----
|
-----
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\CallbackTransformer;
|
|
||||||
use Symfony\Component\Form\Exception\LogicException;
|
use Symfony\Component\Form\Exception\LogicException;
|
||||||
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
|
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
|
||||||
use Symfony\Component\Form\Extension\Core\DataTransformer\StringToFloatTransformer;
|
use Symfony\Component\Form\Extension\Core\DataTransformer\StringToFloatTransformer;
|
||||||
@ -38,19 +37,6 @@ class NumberType extends AbstractType
|
|||||||
|
|
||||||
if ('string' === $options['input']) {
|
if ('string' === $options['input']) {
|
||||||
$builder->addModelTransformer(new StringToFloatTransformer($options['scale']));
|
$builder->addModelTransformer(new StringToFloatTransformer($options['scale']));
|
||||||
$builder->addModelTransformer(new CallbackTransformer(
|
|
||||||
function ($value) {
|
|
||||||
if (\is_float($value) || \is_int($value)) {
|
|
||||||
@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);
|
|
||||||
$value = (string) $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
},
|
|
||||||
function ($value) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,31 +78,27 @@ class NumberTypeTest extends BaseTypeTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
* @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.
|
* @expectedExceptionMessage Expected a numeric string.
|
||||||
*/
|
*/
|
||||||
public function testStringInputWithFloatData(): void
|
public function testStringInputWithFloatData(): void
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, 12345.6789, [
|
$this->factory->create(static::TESTED_TYPE, 12345.6789, [
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
'scale' => 2,
|
'scale' => 2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame('12345,68', $form->createView()->vars['value']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
* @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.
|
* @expectedExceptionMessage Expected a numeric string.
|
||||||
*/
|
*/
|
||||||
public function testStringInputWithIntData(): void
|
public function testStringInputWithIntData(): void
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, 12345, [
|
$this->factory->create(static::TESTED_TYPE, 12345, [
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
'scale' => 2,
|
'scale' => 2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame('12345,00', $form->createView()->vars['value']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultFormattingWithRounding(): void
|
public function testDefaultFormattingWithRounding(): void
|
||||||
|
Reference in New Issue
Block a user