From 89ff3318653396f0dd238de3c44f356ab92a283d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 4 Oct 2018 12:32:57 +0200 Subject: [PATCH] deprecate some options for single_text widgets --- UPGRADE-4.3.md | 6 ++++ UPGRADE-5.0.md | 2 ++ .../AbstractBootstrap3LayoutTest.php | 3 ++ src/Symfony/Component/Form/CHANGELOG.md | 2 ++ .../Form/Extension/Core/Type/DateTimeType.php | 29 +++++++++++++++++-- .../Form/Tests/AbstractLayoutTest.php | 3 ++ .../Form/Tests/Command/DebugCommandTest.php | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 4eb383d467..d9a1bcfa87 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 f446a7c15a..e036966d4b 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 fd1c319a63..4c711b9157 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -1602,6 +1602,9 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest ); } + /** + * @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 17c3839090..6b20f397ed 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 2f9f5c9a54..4c0bdf203f 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 @@ class DateTimeType extends AbstractType // 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 @@ class DateTimeType extends AbstractType '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 f8997d546e..e4ed8bbfc5 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1506,6 +1506,9 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase ); } + /** + * @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 3f4f3b1bff..99391245da 100644 --- a/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php @@ -45,7 +45,7 @@ class DebugCommandTest extends TestCase Built-in form types (Symfony\Component\Form\Extension\Core\Type) ---------------------------------------------------------------- - IntegerType, TimezoneType + DateTimeType, IntegerType, TimezoneType Service form types ------------------