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 83b836d

Browse filesBrowse files
committed
IntegerType: Always use en for IntegerToLocalizedStringTransformer
Fixes #40456
1 parent 5dd56a6 commit 83b836d
Copy full SHA for 83b836d

File tree

Expand file treeCollapse file tree

3 files changed

+39
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+39
-8
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
2424
/**
2525
* Constructs a transformer.
2626
*
27-
* @param bool $grouping Whether thousands should be grouped
28-
* @param int $roundingMode One of the ROUND_ constants in this class
27+
* @param bool $grouping Whether thousands should be grouped
28+
* @param int $roundingMode One of the ROUND_ constants in this class
29+
* @param string|null $locale locale used for transforming
2930
*/
30-
public function __construct($grouping = false, $roundingMode = self::ROUND_DOWN)
31+
public function __construct($grouping = false, $roundingMode = self::ROUND_DOWN, $locale = null)
3132
{
32-
if (\is_int($grouping) || \is_bool($roundingMode) || 2 < \func_num_args()) {
33+
if (\is_int($grouping) || \is_bool($roundingMode) || \is_int($locale)) {
3334
@trigger_error(sprintf('Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.', __CLASS__), \E_USER_DEPRECATED);
3435

3536
$grouping = $roundingMode;
36-
$roundingMode = 2 < \func_num_args() ? func_get_arg(2) : self::ROUND_DOWN;
37+
$roundingMode = null !== $locale ? $locale : self::ROUND_DOWN;
38+
$locale = null;
3739
}
3840

39-
parent::__construct(0, $grouping, $roundingMode);
41+
parent::__construct(0, $grouping, $roundingMode, $locale);
4042
}
4143

4244
/**

‎src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IntegerType extends AbstractType
2525
*/
2626
public function buildForm(FormBuilderInterface $builder, array $options)
2727
{
28-
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
28+
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode'], !$options['grouping'] ? 'en' : null));
2929
}
3030

3131
/**

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php
+30-1Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,42 @@ class IntegerTypeTest extends BaseTypeTest
1717
{
1818
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
1919

20+
private $previousLocale;
21+
2022
protected function setUp(): void
2123
{
2224
IntlTestHelper::requireIntl($this, false);
23-
25+
$this->previousLocale = \Locale::getDefault();
2426
parent::setUp();
2527
}
2628

29+
protected function tearDown(): void
30+
{
31+
\Locale::setDefault($this->previousLocale);
32+
}
33+
34+
public function testArabicLocale()
35+
{
36+
\Locale::setDefault('ar');
37+
38+
$form = $this->factory->create(static::TESTED_TYPE);
39+
$form->submit('123456');
40+
41+
$this->assertSame(123456, $form->getData());
42+
$this->assertSame('123456', $form->getViewData());
43+
}
44+
45+
public function testArabicLocaleNonHtml5()
46+
{
47+
\Locale::setDefault('ar');
48+
49+
$form = $this->factory->create(static::TESTED_TYPE, null, ['grouping' => true]);
50+
$form->submit('123456');
51+
52+
$this->assertSame(123456, $form->getData());
53+
$this->assertSame('١٢٣٬٤٥٦', $form->getViewData());
54+
}
55+
2756
public function testSubmitRejectsFloats()
2857
{
2958
$form = $this->factory->create(static::TESTED_TYPE);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.