8000 [Form] Fix deprecation layer · symfony/symfony@a1e3dea · GitHub
[go: up one dir, main page]

Skip to content

Commit a1e3dea

Browse files
[Form] Fix deprecation layer
1 parent 393c512 commit a1e3dea

22 files changed

+178
-48
lines changed

UPGRADE-6.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ DoctrineBridge
2929
* Deprecate `MessengerTransportDoctrineSchemaSubscriber` in favor of `MessengerTransportDoctrineSchemaListener`
3030
* Deprecate `RememberMeTokenProviderDoctrineSchemaSubscriber` in favor of `RememberMeTokenProviderDoctrineSchemaListener`
3131

32+
Form
33+
----
34+
35+
* Deprecate not configuring the "widget" option of date/time form types, it will default to "single_text" in v7
36+
3237
FrameworkBundle
3338
---------------
3439

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class AbstractBootstrap3HorizontalLayoutTestCase extends AbstractBootst
1515
{
1616
public function testLabelOnForm()
1717
{
18-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
18+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
1919
$view = $form->createView();
2020
$this->renderWidget($view, ['label' => 'foo']);
2121
$html = $this->renderLabel($view);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class AbstractBootstrap3LayoutTestCase extends AbstractLayoutTestCase
1919
{
2020
public function testLabelOnForm()
2121
{
22-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
22+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
2323
$view = $form->createView();
2424
$this->renderWidget($view, ['label' => 'foo']);
2525
$html = $this->renderLabel($view);
@@ -1561,6 +1561,7 @@ public function testDateTime()
15611561
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
15621562
'input' => 'string',
15631563
'with_seconds' => false,
1564+
'widget' => 'choice',
15641565
]);
15651566

15661567
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1598,6 +1599,7 @@ public function testDateTimeWithPlaceholderGlobal()
15981599
'input' => 'string',
15991600
'placeholder' => 'Change&Me',
16001601
'required' => false,
1602+
'widget' => 'choice',
16011603
]);
16021604

16031605
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1637,6 +1639,7 @@ public function testDateTimeWithHourAndMinute()
16371639
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', $data, [
16381640
'input' => 'array',
16391641
'required' => false,
1642+
'widget' => 'choice',
16401643
]);
16411644

16421645
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1674,6 +1677,7 @@ public function testDateTimeWithSeconds()
16741677
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
16751678
'input' => 'string',
16761679
'with_seconds' => true,
1680+
'widget' => 'choice',
16771681
]);
16781682

16791683
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1907,6 +1911,7 @@ public function testBirthDay()
19071911
{
19081912
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '2000-02-03', [
19091913
'input' => 'string',
1914+
'widget' => 'choice',
19101915
]);
19111916

19121917
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1937,6 +1942,7 @@ public function testBirthDayWithPlaceholder()
19371942
'input' => 'string',
19381943
'placeholder' => '',
19391944
'required' => false,
1945+
'widget' => 'choice',
19401946
]);
19411947

19421948
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2465,6 +2471,7 @@ public function testTime()
24652471
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
24662472
'input' => 'string',
24672473
'with_seconds' => false,
2474+
'widget' => 'choice',
24682475
]);
24692476

24702477
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2492,6 +2499,7 @@ public function testTimeWithSeconds()
24922499
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
24932500
'input' => 'string',
24942501
'with_seconds' => true,
2502+
'widget' => 'choice',
24952503
]);
24962504

24972505
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2579,6 +2587,7 @@ public function testTimeWithPlaceholderGlobal()
25792587
'input' => 'string',
25802588
'placeholder' => 'Change&Me',
25812589
'required' => false,
2590+
'widget' => 'choice',
25822591
]);
25832592

25842593
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2606,6 +2615,7 @@ public function testTimeWithPlaceholderOnYear()
26062615
'input' => 'string',
26072616
'required' => false,
26082617
'placeholder' => ['hour' => 'Change&Me'],
2618+
'widget' => 'choice',
26092619
]);
26102620

26112621
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testRow()
4747

4848
public function testLabelOnForm()
4949
{
50-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
50+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
5151
$view = $form->createView();
5252
$this->renderWidget($view, ['label' => 'foo']);
5353
$html = $this->renderLabel($view);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testRow()
5757

5858
public function testLabelOnForm()
5959
{
60-
$form = $this->factory->createNamed('name', DateType::class);
60+
$form = $this->factory->createNamed('name', DateType::class, null, ['widget' => 'choice']);
6161
$view = $form->createView();
6262
$this->renderWidget($view, ['label' => 'foo']);
6363
$html = $this->renderLabel($view);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testRowWithCustomClass()
8686

8787
public function testLabelOnForm()
8888
{
89-
$form = $this->factory->createNamed('name', DateType::class);
89+
$form = $this->factory->createNamed('name', DateType::class, null, ['widget' => 'choice']);
9090
$view = $form->createView();
9191
$this->renderWidget($view, ['label' => 'foo']);
9292
$html = $this->renderLabel($view);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ public function testDateTime()
10061006
$form = $this->factory->createNamed('name', DateTimeType::class, date('Y').'-02-03 04:05:06', [
10071007
'input' => 'string',
10081008
'with_seconds' => false,
1009+
'widget' => 'choice',
10091010
]);
10101011

10111012
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1059,6 +1060,7 @@ public function testDateTimeWithPlaceholderGlobal()
10591060
'input' => 'string',
10601061
'placeholder' => 'Change&Me',
10611062
'required' => false,
1063+
'widget' => 'choice',
10621064
]);
10631065

10641066
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1112,6 +1114,7 @@ public function testDateTimeWithHourAndMinute()
11121114
$form = $this->factory->createNamed('name', DateTimeType::class, $data, [
11131115
'input' => 'array',
11141116
'required' => false,
1117+
'widget' => 'choice',
11151118
]);
11161119

11171120
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1163,6 +1166,7 @@ public function testDateTimeWithSeconds()
11631166
$form = $this->factory->createNamed('name', DateTimeType::class, date('Y').'-02-03 04:05:06', [
11641167
'input' => 'string',
11651168
'with_seconds' => true,
1169+
'widget' => 'choice',
11661170
]);
11671171

11681172
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1387,6 +1391,7 @@ public function testBirthDay()
13871391
{
13881392
$form = $this->factory->createNamed('name', BirthdayType::class, '2000-02-03', [
13891393
'input' => 'string',
1394+
'widget' => 'choice',
13901395
]);
13911396

13921397
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1421,6 +1426,7 @@ public function testBirthDayWithPlaceholder()
14211426
'input' => 'string',
14221427
'placeholder' => '',
14231428
'required' => false,
1429+
'widget' => 'choice',
14241430
]);
14251431

14261432
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1598,6 +1604,7 @@ public function testTime()
15981604
$form = $this->factory->createNamed('name', TimeType::class, '04:05:06', [
15991605
'input' => 'string',
16001606
'with_seconds' => false,
1607+
'widget' => 'choice',
16011608
]);
16021609

16031610
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1631,6 +1638,7 @@ public function testTimeWithSeconds()
16311638
$form = $this->factory->createNamed('name', TimeType::class, '04:05:06', [
16321639
'input' => 'string',
16331640
'with_seconds' => true,
1641+
'widget' => 'choice',
16341642
]);
16351643

16361644
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1714,6 +1722,7 @@ public function testTimeWithPlaceholderGlobal()
17141722
'input' => 'string',
17151723
'placeholder' => 'Change&Me',
17161724
'required' => false,
1725+
'widget' => 'choice',
17171726
]);
17181727

17191728
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1747,6 +1756,7 @@ public function testTimeWithPlaceholderOnYear()
17471756
'input' => 'string',
17481757
'required' => false,
17491758
'placeholder' => ['hour' => 'Change&Me'],
1759+
'widget' => 'choice',
17501760
]);
17511761

17521762
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add a `placeholder_attr` option to `ChoiceType`
8+
* Deprecate not configuring the "widget" option of date/time form types, it will default to "single_text" in v7
89

910
6.2
1011
---

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\Form\FormView;
2727
use Symfony\Component\Form\ReversedTransformer;
2828
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
29+
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2930
use Symfony\Component\OptionsResolver\Options;
3031
use Symfony\Component\OptionsResolver\OptionsResolver;
3132

@@ -243,11 +244,24 @@ public function configureOptions(OptionsResolver $resolver)
243244
'view_timezone' => null,
244245
'format' => self::HTML5_FORMAT,
245246
'date_format' => null,
246-
'widget' => function (Options $options) {
247-
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option is deprecated. It will default to "single_text" in Symfony 7.0.');
247+
'widget' => static function (Options $options) {
248+
try {
249+
if (!$options['date_widget']) {
250+
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option of form type "datetime" is deprecated. It will default to "single_text" in Symfony 7.0.');
251+
252+
return null;
253+
}
254+
} catch (OptionDefinitionException) {
255+
}
256+
257+
try {
258+
if (!$options['time_widget']) {
259+
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option o 97AE f form type "datetime" is deprecated. It will default to "single_text" in Symfony 7.0.');
260+
}
261+
} catch (OptionDefinitionException) {
262+
}
248263

249264
return null;
250-
// return 'single_text';
251265
},
252266
'date_widget' => $dateWidget,
253267
'time_widget' => $timeWidget,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,10 @@ public function configureOptions(OptionsResolver $resolver)
260260
'years' => range((int) date('Y') - 5, (int) date('Y') + 5),
261261
'months' => range(1, 12),
262262
'days' => range(1, 31),
263-
'widget' => function (Options $options) {
264-
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option explicitly is deprecated, its default value will change to "single_text" in 7.0.');
263+
'widget' => static function (Options $options) {
264+
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option of form type "date" is deprecated. It will default to "single_text" in Symfony 7.0.');
265265

266266
return 'choice';
267-
// return 'single_text';
268267
},
269268
'input' => 'datetime',
270269
'format' => $format,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,10 @@ public function configureOptions(OptionsResolver $resolver)
308308
'hours' => range(0, 23),
309309
'minutes' => range(0, 59),
310310
'seconds' => range(0, 59),
311-
'widget' => function (Options $options) {
312-
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option explicitly is deprecated, its default value will change to "single_text" in 7.0.');
311+
'widget' => stat F438 ic function (Options $options) {
312+
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option of form type "time" is deprecated. It will default to "single_text" in Symfony 7.0.');
313313

314314
return 'choice';
315-
// return 'single_text';
316315
},
317316
'input' => 'datetime',
318317
'input_format' => 'H:i:s',

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testLabelWithoutTranslation()
175175

176176
public function testLabelOnForm()
177177
{
178-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType');
178+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', null, ['widget' => 'choice']);
179179
$view = $form->createView();
180180
$this->renderWidget($view, ['label' => 'foo']);
181181
$html = $this->renderLabel($view);
@@ -1327,6 +1327,7 @@ public function testDateTime()
13271327
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
13281328
'input' => 'string',
13291329
'with_seconds' => false,
1330+
'widget' => 'choice',
13301331
]);
13311332

13321333
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1367,6 +1368,7 @@ public function testDateTimeWithPlaceholderGlobal()
13671368
'input' => 'string',
13681369
'placeholder' => 'Change&Me',
13691370
'required' => false,
1371+
'widget' => 'choice',
13701372
]);
13711373

13721374
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1408,6 +1410,7 @@ public function testDateTimeWithHourAndMinute()
14081410
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', $data, [
14091411
'input' => 'array',
14101412
'required' => false,
1413+
'widget' => 'choice',
14111414
]);
14121415

14131416
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1447,6 +1450,7 @@ public function testDateTimeWithSeconds()
14471450
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
14481451
'input' => 'string',
14491452
'with_seconds' => true,
1453+
'widget' => 'choice',
14501454
]);
14511455

14521456
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1654,7 +1658,9 @@ public function testDateSingleText()
16541658
public function testDateErrorBubbling()
16551659
{
16561660
$form = $this->factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType')
1657-
->add('date', 'Symfony\Component\Form\Extension\Core\Type\DateType')
1661+
->add('date', 'Symfony\Component\Form\Extension\Core\Type\DateType', [
1662+
'widget' => 'choice',
1663+
])
16581664
->getForm();
16591665
$form->get('date')->addError(new FormError('[trans]Error![/trans]'));
16601666
$view = $form->createView();
@@ -1667,6 +1673,7 @@ public function testBirthDay()
16671673
{
16681674
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '2000-02-03', [
16691675
'input' => 'string',
1676+
'widget' => 'choice',
16701677
]);
16711678

16721679
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1693,6 +1700,7 @@ public function testBirthDayWithPlaceholder()
16931700
'input' => 'string',
16941701
'placeholder' => '',
16951702
'required' => false,
1703+
'widget' => 'choice',
16961704
]);
16971705

16981706
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2127,6 +2135,7 @@ public function testTime()
21272135
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
21282136
'input' => 'string',
21292137
'with_seconds' => false,
2138+
'widget' => 'choice',
21302139
]);
21312140

21322141
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2151,6 +2160,7 @@ public function testTimeWithSeconds()
21512160
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
21522161
'input' => 'string',
21532162
'with_seconds' => true,
2163+
'widget' => 'choice',
21542164
]);
21552165

21562166
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2230,6 +2240,7 @@ public function testTimeWithPlaceholderGlobal()
22302240
'input' => 'string',
22312241
'placeholder' => 'Change&Me',
22322242
'required' => false,
2243+
'widget' => 'choice',
22332244
]);
22342245

22352246
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2255,6 +2266,7 @@ public function testTimeWithPlaceholderOnYear()
22552266
'input' => 'string',
22562267
'required' => false,
22572268
'placeholder' => ['hour' => 'Change&Me'],
2269+
'widget' => 'choice',
22582270
]);
22592271

22602272
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2277,7 +2289,7 @@ public function testTimeWithPlaceholderOnYear()
22772289
public function testTimeErrorBubbling()
22782290
{
22792291
$form = $this->factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType')
2280-
->add('time', 'Symfony\Component\Form\Extension\Core\Type\TimeType')
2292+
->add('time', 'Symfony\Component\Form\Extension\Core\Type\TimeType', ['widget' => 'choice'])
22812293
->getForm();
22822294
$form->get('time')->addError(new FormError('[trans]Error![/trans]'));
22832295
$view = $form->createView();

0 commit comments

Comments
 (0)
0