8000 feature #31777 [Form] remove deprecated date types options handling (… · symfony/symfony@090cf32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 090cf32

Browse files
committed
feature #31777 [Form] remove deprecated date types options handling (xabbuh)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Form] remove deprecated date types options handling | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 12ed0df remove deprecated date types options handling
2 parents 371dfc7 + 12ed0df commit 090cf32

File tree

7 files changed

+28
-62
lines changed
  • Extension/Core/Type
  • 7 files changed

    +28
    -62
    lines changed

    src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -13,6 +13,7 @@
    1313

    1414
    use Symfony\Component\Form\Extension\Core\Type\PercentType;
    1515
    use Symfony\Component\Form\FormError;
    16+
    use Symfony\Component\Form\FormTypeExtensionInterface;
    1617
    use Symfony\Component\Form\Tests\AbstractLayoutTest;
    1718

    1819
    abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
    @@ -1693,6 +1694,10 @@ public function testDateTimeWithWidgetSingleText()
    16931694
    */
    16941695
    public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
    16951696
    {
    1697+
    if (method_exists(FormTypeExtensionInterface::class, 'getExtendedTypes')) {
    1698+
    $this->markTestSkipped('The test requires symfony/form 4.x.');
    1699+
    }
    1700+
    16961701
    $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [
    16971702
    'input' => 'string',
    16981703
    'date_widget' => 'choice',

    src/Symfony/Component/Form/CHANGELOG.md

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,6 +4,9 @@ CHANGELOG
    44
    5.0.0
    55
    -----
    66

    7+
    * Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
    8+
    set to `single_text` is not supported anymore.
    9+
    * The `format` option of `DateType` and `DateTimeType` cannot be used when the `html5` option is enabled.
    710
    * Using names for buttons that do not start with a letter, a digit, or an underscore throw an exception
    811
    * Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons throw an exception.
    912
    * removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`

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

    Lines changed: 13 additions & 20 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,6 +12,7 @@
    1212
    namespace Symfony\Component\Form\Extension\Core\Type;
    1313

    1414
    use Symfony\Component\Form\AbstractType;
    15+
    use Symfony\Component\Form\Exception\LogicException;
    1516
    use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
    1617
    use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
    1718
    use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
    @@ -159,10 +160,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
    159160
    $dateOptions['input'] = $timeOptions['input'] = 'array';
    160161
    $dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;
    161162

    162-
    if (isset($dateOptions['format']) && DateType::HTML5_FORMAT !== $dateOptions['format']) {
    163-
    $dateOptions['html5'] = false;
    164-
    }
    165-
    166163
    $builder
    167164
    ->addViewTransformer(new DataTransformerChain([
    168165
    new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts),
    @@ -300,37 +297,33 @@ public function configureOptions(OptionsResolver $resolver)
    300297

    301298
    $resolver->setAllowedTypes('input_format', 'string');
    302299

    303-
    $resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
    300+
    $resolver->setNormalizer('date_format', function (Options $options, $dateFormat) {
    304301
    if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
    305-
    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);
    306-
    //throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class));
    302+
    throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class));
    307303
    }
    308304

    309-
    return '';
    305+
    return $dateFormat;
    310306
    });
    311-
    $resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) {
    307+
    $resolver->setNormalizer('date_widget', function (Options $options, $dateWidget) {
    312308
    if (null !== $dateWidget && 'single_text' === $options['widget']) {
    313-
    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);
    314-
    //throw new LogicException(sprintf('Cannot use the "date_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
    309+
    throw new LogicException(sprintf('Cannot use the "date_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
    315310
    }
    316311

    317-
    return '';
    312+
    return $dateWidget;
    318313
    });
    319-
    $resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) {
    314+
    $resolver->setNormalizer('time_widget', function (Options $options, $timeWidget) {
    320315
    if (null !== $timeWidget && 'single_text' === $options['widget']) {
    321-
    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);
    322-
    //throw new LogicException(sprintf('Cannot use the "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
    316+
    throw new LogicException(sprintf('Cannot use the "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
    323317
    }
    324318

    325-
    return '';
    319+
    return $timeWidget;
    326320
    });
    327-
    $resolver->setDeprecated('html5', function (Options $options, $html5) {
    321+
    $resolver->setNormalizer('html5', function (Options $options, $html5) {
    328322
    if ($html5 && self::HTML5_FORMAT !== $options['format']) {
    329-
    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);
    330-
    //throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
    323+
    throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
    331324
    }
    332325

    333-
    return '';
    326+
    return $html5;
    334327
    });
    335328
    }
    336329

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

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,6 +12,7 @@
    1212
    namespace Symfony\Component\Form\Extension\Core\Type;
    1313

    1414
    use Symfony\Component\Form\AbstractType;
    15+
    use Symfony\Component\Form\Exception\LogicException;
    1516
    use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
    1617
    use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
    1718
    use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
    @@ -308,13 +309,12 @@ public function configureOptions(OptionsResolver $resolver)
    308309
    $resolver->setAllowedTypes('days', 'array');
    309310
    $resolver->setAllowedTypes('input_format', 'string');
    310311

    311-
    $resolver->setDeprecated('html5', function (Options $options, $html5) {
    312+
    $resolver->setNormalizer('html5', function (Options $options, $html5) {
    312313
    if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
    313-
    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);
    314-
    //throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
    314+
    throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
    315315
    }
    316316

    317-
    return '';
    317+
    return $html5;
    318318
    });
    319319
    }
    320320

    src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

    Lines changed: 0 additions & 23 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1509,29 +1509,6 @@ public function testDateTimeWithWidgetSingleText()
    15091509
    );
    15101510
    }
    15111511

    1512-
    /**
    1513-
    * @group legacy
    1514-
    */
    1515-
    public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
    1516-
    {
    1517-
    $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [
    1518-
    'input' => 'string',
    1519-
    'date_widget' => 'choice',
    1520-
    'time_widget' => 'choice',
    1521-
    'widget' => 'single_text',
    1522-
    'model_timezone' => 'UTC',
    1523-
    'view_timezone' => 'UTC',
    1524-
    ]);
    1525-
    1526-
    $this->assertWidgetMatchesXpath($form->createView(), [],
    1527-
    '/input
    1528-
    [@type="datetime-local"]
    1529-
    [@name="name"]
    1530-
    [@value="2011-02-03T04:05:06"]
    1531-
    '
    1532-
    );
    1533-
    }
    1534-
    15351512
    public function testDateChoice()
    15361513
    {
    15371514
    $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', date('Y').'-02-03', [

    src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -45,7 +45,7 @@ public function testDebugDeprecatedDefaults()
    4545
    Built-in form types (Symfony\Component\Form\Extension\Core\Type)
    4646
    ----------------------------------------------------------------
    4747
    48-
    BirthdayType, DateTimeType, DateType, IntegerType
    48+
    IntegerType
    4949
    5050
    Service form types
    5151
    ------------------

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

    Lines changed: 2 additions & 14 deletions
    Original file line numberDiff line numberDiff line change
    @@ -301,6 +301,7 @@ public function testSubmitStringSingleTextWithSeconds()
    301301
    public function testSubmitDifferentPattern()
    302302
    {
    303303
    $form = $this->factory->create(static::TESTED_TYPE, null, [
    304+
    'html5' => false,
    304305
    'date_format' => 'MM*yyyy*dd',
    305306
    'date_widget' => 'single_text',
    306307
    'time_widget' => 'single_text',
    @@ -470,20 +471,6 @@ public function testDontPassHtml5TypeIfHtml5NotAllowed()
    470471
    $this->assertArrayNotHasKey('type', $view->vars);
    471472
    }
    472473

    473-
    /**
    474-
    * @group legacy
    475-
    */
    476-
    public function testDontPassHtml5TypeIfNotHtml5Format()
    477-
    {
    478-
    $view = $this->factory->create(static::TESTED_TYPE, null, [
    479-
    'widget' => 'single_text',
    480-
    'format' => 'yyyy-MM-dd HH:mm',
    481-
    ])
    482-
    ->createView();
    483-
    484-
    $this->assertArrayNotHasKey('type', $view->vars);
    485-
    }
    486-
    487474
    public function testDontPassHtml5TypeIfNotSingleText()
    488475
    {
    489476
    $view = $this->factory->create(static::TESTED_TYPE, null, [
    @@ -497,6 +484,7 @@ public function testDontPassHtml5TypeIfNotSingleText()
    497484
    public function testSingleTextWidgetWithCustomNonHtml5Format()
    498485
    {
    499486
    $form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [
    487+
    'html5' => false,
    500488
    'widget' => 'single_text',
    501489
    'date_format' => \IntlDateFormatter::SHORT,
    502490
    'format' => null,

    0 commit comments

    Comments
     (0)
    0