From 12ed0df2239916ab4654230ddd148a4922766814 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 31 May 2019 13:24:23 +0200 Subject: [PATCH] remove deprecated date types options handling --- .../AbstractBootstrap3LayoutTest.php | 5 +++ src/Symfony/Component/Form/CHANGELOG.md | 3 ++ .../Form/Extension/Core/Type/DateTimeType.php | 33 ++++++++----------- .../Form/Extension/Core/Type/DateType.php | 8 ++--- .../Form/Tests/AbstractLayoutTest.php | 23 ------------- .../Form/Tests/Command/DebugCommandTest.php | 2 +- .../Extension/Core/Type/DateTimeTypeTest.php | 16 ++------- 7 files changed, 28 insertions(+), 62 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index b332ff018d74..540d23c8a6e7 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -13,6 +13,7 @@ use Symfony\Component\Form\Extension\Core\Type\PercentType; use Symfony\Component\Form\FormError; +use Symfony\Component\Form\FormTypeExtensionInterface; use Symfony\Component\Form\Tests\AbstractLayoutTest; abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest @@ -1693,6 +1694,10 @@ public function testDateTimeWithWidgetSingleText() */ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets() { + if (method_exists(FormTypeExtensionInterface::class, 'getExtendedTypes')) { + $this->markTestSkipped('The test requires symfony/form 4.x.'); + } + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [ 'input' => 'string', 'date_widget' => 'choice', diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 34d3d196d439..264396a0de7e 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -4,6 +4,9 @@ CHANGELOG 5.0.0 ----- + * 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 `format` option of `DateType` and `DateTimeType` cannot be used when the `html5` option is enabled. * Using names for buttons that do not start with a letter, a digit, or an underscore throw an exception * Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons throw an exception. * removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType` diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index 4e84b71a7c8e..3bd61df51369 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer; @@ -159,10 +160,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $dateOptions['input'] = $timeOptions['input'] = 'array'; $dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true; - if (isset($dateOptions['format']) && DateType::HTML5_FORMAT !== $dateOptions['format']) { - $dateOptions['html5'] = false; - } - $builder ->addViewTransformer(new DataTransformerChain([ new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts), @@ -300,37 +297,33 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('input_format', 'string'); - $resolver->setDeprecated('date_format', function (Options $options, $dateFormat) { + $resolver->setNormalizer('date_format', function (Options $options, $dateFormat) { 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)); + throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class)); } - return ''; + return $dateFormat; }); - $resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) { + $resolver->setNormalizer('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)); + 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 ''; + return $dateWidget; }); - $resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) { + $resolver->setNormalizer('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)); + 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 ''; + return $timeWidget; }); - $resolver->setDeprecated('html5', function (Options $options, $html5) { + $resolver->setNormalizer('html5', function (Options $options, $html5) { if ($html5 && self::HTML5_FORMAT !== $options['format']) { - return sprintf('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); - //throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class)); + throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class)); } - return ''; + return $html5; }); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 39002df2b6d2..03e55ce13d26 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; @@ -308,13 +309,12 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('days', 'array'); $resolver->setAllowedTypes('input_format', 'string'); - $resolver->setDeprecated('html5', function (Options $options, $html5) { + $resolver->setNormalizer('html5', function (Options $options, $html5) { if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) { - return sprintf('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); - //throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class)); + throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class)); } - return ''; + return $html5; }); } diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index b03ac0f9fc4d..16344f9149d4 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1509,29 +1509,6 @@ 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', [ - 'input' => 'string', - 'date_widget' => 'choice', - 'time_widget' => 'choice', - 'widget' => 'single_text', - 'model_timezone' => 'UTC', - 'view_timezone' => 'UTC', - ]); - - $this->assertWidgetMatchesXpath($form->createView(), [], -'/input - [@type="datetime-local"] - [@name="name"] - [@value="2011-02-03T04:05:06"] -' - ); - } - public function testDateChoice() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', date('Y').'-02-03', [ diff --git a/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php b/src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php index f2a1b89f0e10..a2d105d2236f 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) ---------------------------------------------------------------- - BirthdayType, DateTimeType, DateType, IntegerType + IntegerType Service form types ------------------ 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 93935157fe9c..f898212b3bc9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -301,6 +301,7 @@ public function testSubmitStringSingleTextWithSeconds() public function testSubmitDifferentPattern() { $form = $this->factory->create(static::TESTED_TYPE, null, [ + 'html5' => false, 'date_format' => 'MM*yyyy*dd', 'date_widget' => 'single_text', 'time_widget' => 'single_text', @@ -470,20 +471,6 @@ public function testDontPassHtml5TypeIfHtml5NotAllowed() $this->assertArrayNotHasKey('type', $view->vars); } - /** - * @group legacy - */ - public function testDontPassHtml5TypeIfNotHtml5Format() - { - $view = $this->factory->create(static::TESTED_TYPE, null, [ - 'widget' => 'single_text', - 'format' => 'yyyy-MM-dd HH:mm', - ]) - ->createView(); - - $this->assertArrayNotHasKey('type', $view->vars); - } - public function testDontPassHtml5TypeIfNotSingleText() { $view = $this->factory->create(static::TESTED_TYPE, null, [ @@ -497,6 +484,7 @@ public function testDontPassHtml5TypeIfNotSingleText() public function testSingleTextWidgetWithCustomNonHtml5Format() { $form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [ + 'html5' => false, 'widget' => 'single_text', 'date_format' => \IntlDateFormatter::SHORT, 'format' => null,