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

Commitd28182f

Browse files
committed
[Form] Fix custom formats deprecation with HTML5 widgets
1 parent02be26a commitd28182f

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
useSymfony\Component\Form\FormView;
2626
useSymfony\Component\Form\ReversedTransformer;
2727
useSymfony\Component\OptionsResolver\Exception\InvalidOptionsException;
28+
useSymfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2829
useSymfony\Component\OptionsResolver\Options;
2930
useSymfony\Component\OptionsResolver\OptionsResolver;
3031

@@ -344,14 +345,23 @@ public function configureOptions(OptionsResolver $resolver)
344345

345346
return'';
346347
});
347-
$resolver->setDeprecated('html5',function (Options$options,$html5) {
348-
if ($html5 &&self::HTML5_FORMAT !==$options['format']) {
349-
returnsprintf('Using a custom format when the "html5" option of %s is enabled is deprecated since Symfony 4.3 and will lead to an exception in 5.0.',self::class);
350-
//throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
351-
}
352-
353-
return'';
354-
});
348+
foreach (['html5','format']as$option) {
349+
$resolver->setDeprecated($option,staticfunction (Options$options,$value)use ($option):string {
350+
try {
351+
$html5 ='html5' ===$option ?$value :$options['html5'];
352+
$format ='format' ===$option ?$value :$options['format'];
353+
}catch (OptionDefinitionException$e) {
354+
return'';
355+
}
356+
357+
if ($html5 &&self::HTML5_FORMAT !==$format) {
358+
returnsprintf('Using a custom format when the "html5" option of %s is enabled is deprecated since Symfony 4.3 and will lead to an exception in 5.0.',self::class);
359+
//throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
360+
}
361+
362+
return'';
363+
});
364+
}
355365
}
356366

357367
/**

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\Form\FormView;
2323
useSymfony\Component\Form\ReversedTransformer;
2424
useSymfony\Component\OptionsResolver\Exception\InvalidOptionsException;
25+
useSymfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2526
useSymfony\Component\OptionsResolver\Options;
2627
useSymfony\Component\OptionsResolver\OptionsResolver;
2728

@@ -322,14 +323,24 @@ public function configureOptions(OptionsResolver $resolver)
322323
$resolver->setAllowedTypes('days','array');
323324
$resolver->setAllowedTypes('input_format','string');
324325

325-
$resolver->setDeprecated('html5',function (Options$options,$html5) {
326-
if ($html5 &&'single_text' ===$options['widget'] &&self::HTML5_FORMAT !==$options['format']) {
327-
returnsprintf('Using a custom format when the "html5" option of %s is enabled is deprecated since Symfony 4.3 and will lead to an exception in 5.0.',self::class);
328-
//throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
329-
}
326+
foreach (['html5','widget','format']as$option) {
327+
$resolver->setDeprecated($option,staticfunction (Options$options,$value)use ($option):string {
328+
try {
329+
$html5 ='html5' ===$option ?$value :$options['html5'];
330+
$widget ='widget' ===$option ?$value :$options['widget'];
331+
$format ='format' ===$option ?$value :$options['format'];
332+
}catch (OptionDefinitionException$e) {
333+
return'';
334+
}
330335

331-
return'';
332-
});
336+
if ($html5 &&'single_text' ===$widget &&self::HTML5_FORMAT !==$format) {
337+
returnsprintf('Using a custom format when the "html5" option of %s is enabled is deprecated since Symfony 4.3 and will lead to an exception in 5.0.',self::class);
338+
//throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
339+
}
340+
341+
return'';
342+
});
343+
}
333344
}
334345

335346
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ public function testSingleTextWidgetWithCustomNonHtml5Format()
532532
'widget' =>'single_text',
533533
'date_format' => \IntlDateFormatter::SHORT,
534534
'format' =>null,
535+
'html5' =>false,
535536
]);
536537
$view =$form->createView();
537538

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp