8000 minor #30230 [Form] undeprecate date formats in single_text widgets (… · enumag/symfony@c3cf08e · GitHub
[go: up one dir, main page]

Skip to content

Commit c3cf08e

Browse files
committed
minor symfony#30230 [Form] undeprecate date formats in single_text widgets (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] undeprecate date formats in single_text widgets | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 1a983d0 undeprecate date formats in single_text widgets
2 parents ccd4bbe + 1a983d0 commit c3cf08e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ public function configureOptions(OptionsResolver $resolver)
294294
]);
295295

296296
$resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
297-
if (null !== $dateFormat && 'single_text' === $options['widget']) {
298-
return sprintf('Using the "date_format" option of %s when the "widget" option is set to "single_text" is deprecated since Symfony 4.3 and will lead to an exception in 5.0.', self::class);
299-
//throw new LogicException(sprintf('Cannot use the "date_format" option of the %s when the "widget" option is set to "single_text".', self::class));
297+
if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
298+
return sprintf('Using the "date_format" option of %s with an HTML5 date widget is deprecated since Symfony 4.3 and will lead to an exception in 5.0.', self::class);
299+
//throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class));
300300
}
301301

302302
return '';

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ public function testDontPassHtml5TypeIfNotSingleText()
491491
$this->assertArrayNotHasKey('type', $view->vars);
492492
}
493493

494+
public function testSingleTextWidgetWithCustomNonHtml5Format()
495+
{
496+
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [
497+
'widget' => 'single_text',
498+
'date_format' => \IntlDateFormatter::SHORT,
499+
'format' => null,
500+
]);
501+
$view = $form->createView();
502+
503+
$this->assertSame('2/13/19, 7:12:13 PM', $view->vars['value']);
504+
}
505+
494506
public function testDateTypeChoiceErrorsBubbleUp()
495507
{
496508
$error = new FormError('Invalid!');

0 commit comments

Comments
 (0)
0