From 1a983d07dbd5ef44f262f2ce6263ce2dbd6c9d1d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 13 Feb 2019 19:21:50 +0100 Subject: [PATCH] undeprecate date formats in single_text widgets --- .../Form/Extension/Core/Type/DateTimeType.php | 6 +++--- .../Tests/Extension/Core/Type/DateTimeTypeTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index 4c0bdf203f..4109c1d7c0 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -294,9 +294,9 @@ class DateTimeType extends AbstractType ]); $resolver->setDeprecated('date_format', function (Options $options, $dateFormat) { - if (null !== $dateFormat && 'single_text' === $options['widget']) { - 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); - //throw new LogicException(sprintf('Cannot use the "date_format" option of the %s when the "widget" option is set to "single_text".', self::class)); + if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { + 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); + //throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class)); } return ''; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index 4f4966c5f8..ac04761a81 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -491,6 +491,18 @@ class DateTimeTypeTest extends BaseTypeTest $this->assertArrayNotHasKey('type', $view->vars); } + public function testSingleTextWidgetWithCustomNonHtml5Format() + { + $form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [ + 'widget' => 'single_text', + 'date_format' => \IntlDateFormatter::SHORT, + 'format' => null, + ]); + $view = $form->createView(); + + $this->assertSame('2/13/19, 7:12:13 PM', $view->vars['value']); + } + public function testDateTypeChoiceErrorsBubbleUp() { $error = new FormError('Invalid!');