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

Skip to content

Commit 04fac82

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

19 files changed

+201
-30
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ 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, [
19+
'widget' => 'choice',
20+
]);
1921
$view = $form->createView();
2022
$this->renderWidget($view, ['label' => 'foo']);
2123
$html = $this->renderLabel($view);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ 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, [
23+
'widget' => 'choice',
24+
]);
2325
$view = $form->createView();
2426
$this->renderWidget($view, ['label' => 'foo']);
2527
$html = $this->renderLabel($view);
@@ -1561,6 +1563,7 @@ public function testDateTime()
15611563
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
15621564
'input' => 'string',
15631565
'with_seconds' => false,
1566+
'widget' => 'choice',
15641567
]);
15651568

15661569
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1598,6 +1601,7 @@ public function testDateTimeWithPlaceholderGlobal()
15981601
'input' => 'string',
15991602
'placeholder' => 'Change&Me',
16001603
'required' => false,
1604+
'widget' => 'choice',
16011605
]);
16021606

16031607
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1637,6 +1641,7 @@ public function testDateTimeWithHourAndMinute()
16371641
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', $data, [
16381642
'input' => 'array',
16391643
'required' => false,
1644+
'widget' => 'choice',
16401645
]);
16411646

16421647
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1674,6 +1679,7 @@ public function testDateTimeWithSeconds()
16741679
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
16751680
'input' => 'string',
16761681
'with_seconds' => true,
1682+
'widget' => 'choice',
16771683
]);
16781684

16791685
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1907,6 +1913,7 @@ public function testBirthDay()
19071913
{
19081914
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '2000-02-03', [
19091915
'input' => 'string',
1916+
'widget' => 'choice',
19101917
]);
19111918

19121919
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -1937,6 +1944,7 @@ public function testBirthDayWithPlaceholder()
19371944
'input' => 'string',
19381945
'placeholder' => '',
19391946
'required' => false,
1947+
'widget' => 'choice',
19401948
]);
19411949

19421950
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2465,6 +2473,7 @@ public function testTime()
24652473
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
24662474
'input' => 'string',
24672475
'with_seconds' => false,
2476+
'widget' => 'choice',
24682477
]);
24692478

24702479
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2492,6 +2501,7 @@ public function testTimeWithSeconds()
24922501
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
24932502
'input' => 'string',
24942503
'with_seconds' => true,
2504+
'widget' => 'choice',
24952505
]);
24962506

24972507
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2579,6 +2589,7 @@ public function testTimeWithPlaceholderGlobal()
25792589
'input' => 'string',
25802590
'placeholder' => 'Change&Me',
25812591
'required' => false,
2592+
'widget' => 'choice',
25822593
]);
25832594

25842595
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
@@ -2606,6 +2617,7 @@ public function testTimeWithPlaceholderOnYear()
26062617
'input' => 'string',
26072618
'required' => false,
26082619
'placeholder' => ['hour' => 'Change&Me'],
2620+
'widget' => 'choice',
26092621
]);
26102622

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ 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, [
51+
'widget' => 'choice',
52+
]);
5153
$view = $form->createView();
5254
$this->renderWidget($view, ['label' => 'foo']);
5355
$html = $this->renderLabel($view);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ 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, [
61+
'widget' => 'choice',
62+
]);
6163
$view = $form->createView();
6264
$this->renderWidget($view, ['label' => 'foo']);
6365
$html = $this->renderLabel($view);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ 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, [
90+
'widget' => 'choice',
91+
]);
9092
$view = $form->createView();
9193
$this->renderWidget($view, ['label' => 'foo']);
9294
$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/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 of 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' => static 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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ 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, [
179+
'widget' => 'choice',
180+
]);
179181
$view = $form->createView();
180182
$this->renderWidget($view, ['label' => 'foo']);
181183
$html = $this->renderLabel($view);
@@ -1327,6 +1329,7 @@ public function testDateTime()
13271329
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
13281330
'input' => 'string',
13291331
'with_seconds' => false,
1332+
'widget' => 'choice',
13301333
]);
13311334

13321335
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1367,6 +1370,7 @@ public function testDateTimeWithPlaceholderGlobal()
13671370
'input' => 'string',
13681371
'placeholder' => 'Change&Me',
13691372
'required' => false,
1373+
'widget' => 'choice',
13701374
]);
13711375

13721376
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1408,6 +1412,7 @@ public function testDateTimeWithHourAndMinute()
14081412
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', $data, [
14091413
'input' => 'array',
14101414
'required' => false,
1415+
'widget' => 'choice',
14111416
]);
14121417

14131418
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1447,6 +1452,7 @@ public function testDateTimeWithSeconds()
14471452
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', date('Y').'-02-03 04:05:06', [
14481453
'input' => 'string',
14491454
'with_seconds' => true,
1455+
'widget' => 'choice',
14501456
]);
14511457

14521458
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1654,7 +1660,9 @@ public function testDateSingleText()
16541660
public function testDateErrorBubbling()
16551661
{
16561662
$form = $this->factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType')
1657-
->add('date', 'Symfony\Component\Form\Extension\Core\Type\DateType')
1663+
->add('date', 'Symfony\Component\Form\Extension\Core\Type\DateType', [
1664+
'widget' => 'choice',
1665+
])
16581666
->getForm();
16591667
$form->get('date')->addError(new FormError('[trans]Error![/trans]'));
16601668
$view = $form->createView();
@@ -1667,6 +1675,7 @@ public function testBirthDay()
16671675
{
16681676
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\BirthdayType', '2000-02-03', [
16691677
'input' => 'string',
1678+
'widget' => 'choice',
16701679
]);
16711680

16721681
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -1693,6 +1702,7 @@ public function testBirthDayWithPlaceholder()
16931702
'input' => 'string',
16941703
'placeholder' => '',
16951704
'required' => false,
1705+
'widget' => 'choice',
16961706
]);
16971707

16981708
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2127,6 +2137,7 @@ public function testTime()
21272137
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
21282138
'input' => 'string',
21292139
'with_seconds' => false,
2140+
'widget' => 'choice',
21302141
]);
21312142

21322143
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2151,6 +2162,7 @@ public function testTimeWithSeconds()
21512162
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TimeType', '04:05:06', [
21522163
'input' => 'string',
21532164
'with_seconds' => true,
2165+
'widget' => 'choice',
21542166
]);
21552167

21562168
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2230,6 +2242,7 @@ public function testTimeWithPlaceholderGlobal()
22302242
'input' => 'string',
22312243
'placeholder' => 'Change&Me',
22322244
'required' => false,
2245+
'widget' => 'choice',
22332246
]);
22342247

22352248
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2255,6 +2268,7 @@ public function testTimeWithPlaceholderOnYear()
22552268
'input' => 'string',
22562269
'required' => false,
22572270
'placeholder' => ['hour' => 'Change&Me'],
2271+
'widget' => 'choice',
22582272
]);
22592273

22602274
$this->assertWidgetMatchesXpath($form->createView(), [],
@@ -2277,7 +2291,7 @@ public function testTimeWithPlaceholderOnYear()
22772291
public function testTimeErrorBubbling()
22782292
{
22792293
$form = $this->factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType')
2280-
->add('time', 'Symfony\Component\Form\Extension\Core\Type\TimeType')
2294+
->add('time', 'Symfony\Component\Form\Extension\Core\Type\TimeType', ['widget' => 'choice'])
22812295
->getForm();
22822296
$form->get('time')->addError(new FormError('[trans]Error![/trans]'));
22832297
$view = $form->createView();

0 commit comments

Comments
 (0)
0