10000 [Form] Fix deprecation layer · symfony/symfony@1ca33e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ca33e7

Browse files
[Form] Fix deprecation layer
1 parent f4348ea commit 1ca33e7

21 files changed

+170
-59
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< F438 /span>->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
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Don't render seconds for HTML5 date pickers unless "with_seconds" is explicitly set
88
* Add a `placeholder_attr` option to `ChoiceType`
9+
* Deprecate not configuring the "widget" option of date/time form types, it will default to "single_text" in v7
910

1011
6.2
1112
---

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

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
148148
$timeOptions['label'] = false;
149149
}
150150

151-
if (null !== $options['date_widget']) {
152-
$dateOptions['widget'] = $options['date_widget'];
153-
}
151+
$dateOptions['widget'] = $options['date_widget'] ?? $options['widget'] ?? 'choice';
152+
$timeOptions['widget'] = $options['time_widget'] ?? $options['widget'] ?? 'choice';
154153

155154
if (null !== $options['date_label']) {
156155
$dateOptions['label'] = $options['date_label'];
157156
}
158157

159-
if (null !== $options['time_widget']) {
160-
$timeOptions['widget'] = $options['time_widget'];
161-
}
162-
163158
if (null !== $options['time_label']) {
164159
$timeOptions['label'] = $options['time_label'];
165160
}
@@ -236,26 +231,15 @@ public function configureOptions(OptionsResolver $resolver)
236231
{
237232
$compound = static fn (Options $options) => 'single_text' !== $options['widget'];
238233

239-
// Defaults to the value of "widget"
240-
$dateWidget = static fn (Options $options) => 'single_text' === $options['widget'] ? null : $options['widget'];
241-
242-
// Defaults to the value of "widget"
243-
$timeWidget = static fn (Options $options) => 'single_text' === $options['widget'] ? null : $options['widget'];
244-
245234
$resolver->setDefaults([
246235
'input' => 'datetime',
247236
'model_timezone' => null,
248237
'view_timezone' => null,
249238
'format' => self::HTML5_FORMAT,
250239
'date_format' => null,
251-
'widget' => function (Options $options) {
252-
trigger_deprecation('symfony/form', '6.3', 'Not configuring the "widget" option is deprecated. It will default to "single_text" in Symfony 7.0.');
253-
254-
return null;
255-
// return 'single_text';
256-
},
257-
'date_widget' => $dateWidget,
258-
'time_widget' => $timeWidget,
240+
'widget' => null,
241+
'date_widget' => null,
242+
'time_widget' => null,
259243
'with_minutes' => true,
260244
'with_seconds' => false,
261245
'html5' => true,
@@ -325,19 +309,20 @@ public function configureOptions(OptionsResolver $resolver)
325309

326310
return $dateFormat;
327311
});
328-
$resolver->setNormalizer('date_widget', static function (Options $options, $dateWidget) {
329-
if (null !== $dateWidget && 'single_text' === $options['widget']) {
330-
throw new LogicException(sprintf('Cannot use the "date_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
331-
}
332-
333-
return $dateWidget;
334-
});
335-
$resolver->setNormalizer('time_widget', static function (Options $options, $timeWidget) {
336-
if (null !== $timeWidget && 'single_text' === $options['widget']) {
337-
throw new LogicException(sprintf('Cannot use the "time_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
312+
$resolver->setNormalizer('widget', static function (Options $options, $widget) {
313+
if ('single_text' === $widget) {
314+
if (null !== $options['date_widget']) {
315+
throw new LogicException(sprintf('Cannot use the "date_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
316+
}
317+
if (null !== $options['time_widget']) {
318+
throw new LogicException(sprintf('Cannot use the "time_widget" option of the "%s" when the "widget" option is set to "single_text".', self::class));
319+
}
320+
} elseif (null === $widget && null === $options['date_widget'] && null === $options['time_widget']) {
321+
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.');
322+
// return 'single_text';
338323
}
339324

340-
return $timeWidget;
325+
return $widget;
341326
});
342327
$resolver->setNormalizer('html5', static function (Options $options, $html5) {
343328
if ($html5 && self::HTML5_FORMAT !== $options['format']) {

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
@@ -312,11 +312,10 @@ public function configureOptions(OptionsResolver $resolver)
312312
'hours' => range(0, 23),
313313
'minutes' => range(0, 59),
314314
'seconds' => range(0, 59),
315-
'widget' => function (Options $options) {
316-
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.');
315+
'widget' => static function (Options $options) {
316+
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.');
317317

318318
return 'choice';
319-
// return 'single_text';
320319
},
321320
'input' => 'datetime',
322321
'input_format' => 'H:i:s',

0 commit comments

Comments
 (0)
0