diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 4eb383d46710..d9a1bcfa871a 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -13,6 +13,12 @@ Config * Deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` +Form +---- + + * Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is + set to `single_text` is deprecated. + FrameworkBundle --------------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index f446a7c15a37..e036966d4b9d 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -76,6 +76,8 @@ Finder Form ---- + * Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is + set to `single_text` is not supported anymore. * The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static `getExtendedTypes()` method which must return an iterable of extended types. diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index fd1c319a6310..4c711b915784 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -1602,6 +1602,9 @@ public function testDateTimeWithWidgetSingleText() ); } + /** + * @group legacy + */ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [ diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 17c383909086..6b20f397ed74 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 4.3.0 ----- + * deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` + option is set to `single_text` * added `block_prefix` option to `BaseType`. 4.2.0 diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index 2f9f5c9a549c..4c0bdf203f06 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -216,12 +216,12 @@ public function configureOptions(OptionsResolver $resolver) // Defaults to the value of "widget" $dateWidget = function (Options $options) { - return $options['widget']; + return 'single_text' === $options['widget'] ? null : $options['widget']; }; // Defaults to the value of "widget" $timeWidget = function (Options $options) { - return $options['widget']; + return 'single_text' === $options['widget'] ? null : $options['widget']; }; $resolver->setDefaults([ @@ -292,6 +292,31 @@ public function configureOptions(OptionsResolver $resolver) 'text', 'choice', ]); + + $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)); + } + + return ''; + }); + $resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) { + if (null !== $dateWidget && 'single_text' === $options['widget']) { + return sprintf('Using the "date_widget" 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_widget" option of the %s when the "widget" option is set to "single_text".', self::class)); + } + + return ''; + }); + $resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) { + if (null !== $timeWidget && 'single_text' === $options['widget']) { + return sprintf('Using the "time_widget" 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 "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class)); + } + + return ''; + }); } /** diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index f8997d546e64..e4ed8bbfc5fa 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1506,6 +1506,9 @@ public function testDateTimeWithWidgetSingleText() ); } + /** + * @group legacy + */ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [ diff --git a/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php b/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php index 3f4f3b1bff09..99391245da97 100644 --- a/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php @@ -45,7 +45,7 @@ public function testDebugDeprecatedDefaults() Built-in form types (Symfony\Component\Form\Extension\Core\Type) ---------------------------------------------------------------- - IntegerType, TimezoneType + DateTimeType, IntegerType, TimezoneType Service form types ------------------