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 957265a

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

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+30
-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
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ 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;
39+
}
40+
if (null === $locale) {
41+
parent::__construct(0, $grouping, $roundingMode);
42+
} else {
43+
parent::__construct(0, $grouping, $roundingMode, $locale);
3744
}
38-
39-
parent::__construct(0, $grouping, $roundingMode);
4045
}
4146

4247
/**

‎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
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ 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+
$locale = $options['grouping'] ? \Locale::getDefault() : 'en';
29+
$builder->addViewTransformer(
30+
new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode'], $locale)
31+
);
2932
}
3033

3134
/**

‎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
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ protected function setUp(): void
2424
parent::setUp();
2525
}
2626

27+
public function testArabicLocale()
28+
{
29+
$default = \Locale::getDefault();
30+
\Locale::setDefault('ar');
31+
32+
$form = $this->factory->create(static::TESTED_TYPE);
33+
$form->submit('123456');
34+
35+
$this->assertSame(123456, $form->getData());
36+
$this->assertSame('123456', $form->getViewData());
37+
38+
\Locale::setDefault($default);
39+
}
40+
2741
public function testSubmitRejectsFloats()
2842
{
2943
$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.