Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit957265a

Browse files
committed
IntegerType: Always use en for IntegerToLocalizedStringTransformer
Fixes#40456
1 parent5dd56a6 commit957265a

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

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

Lines 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-
publicfunction__construct($grouping =false,$roundingMode =self::ROUND_DOWN)
31+
publicfunction__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‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class IntegerType extends AbstractType
2525
*/
2626
publicfunctionbuildForm(FormBuilderInterface$builder,array$options)
2727
{
28-
$builder->addViewTransformer(newIntegerToLocalizedStringTransformer($options['grouping'],$options['rounding_mode']));
28+
$locale =$options['grouping'] ? \Locale::getDefault() :'en';
29+
$builder->addViewTransformer(
30+
newIntegerToLocalizedStringTransformer($options['grouping'],$options['rounding_mode'],$locale)
31+
);
2932
}
3033

3134
/**

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

Lines 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+
publicfunctiontestArabicLocale()
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
publicfunctiontestSubmitRejectsFloats()
2842
{
2943
$form =$this->factory->create(static::TESTED_TYPE);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp