8000 feature #28723 [Form] deprecate custom formats with HTML5 widgets (xa… · symfony/symfony@93c2feb · GitHub
[go: up one dir, main page]

Skip to content

Commit 93c2feb

Browse files
committed
feature #28723 [Form] deprecate custom formats with HTML5 widgets (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] deprecate custom formats with HTML5 widgets | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#10986 Commits ------- b70c1b6 deprecate custom formats with HTML5 widgets
2 parents 3560cfd + b70c1b6 commit 93c2feb

File tree

8 files changed

+44
-3
lines changed

8 files changed

+44
-3
lines changed

UPGRADE-4.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Config
2323
Form
2424
----
2525

26+
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
2627
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
2728
exception in 5.0.
2829
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions< 10000 div class="d-flex">
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Finder
7878
Form
7979
----
8080

81+
* Removed support for using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled.
8182
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
8283
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
8384
exception.

src/Symfony/Component/Form/CHANGELOG.md

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

7+
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
78
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
89
exception in 5.0.
910
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
159159
$dateOptions['input'] = $timeOptions['input'] = 'array';
160160
$dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;
161161

162+
if (isset($dateOptions['format']) && DateType::HTML5_FORMAT !== $dateOptions['format']) {
163+
$dateOptions['html5'] = false;
164+
}
165+
162166
$builder
163167
->addViewTransformer(new DataTransformerChain([
164168
new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts),
@@ -294,6 +298,8 @@ public function configureOptions(OptionsResolver $resolver)
294298
'choice',
295299
]);
296300

301+
$resolver->setAllowedTypes('input_format', 'string');
302+
297303
$resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
298304
if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
299305
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);
@@ -318,8 +324,14 @@ public function configureOptions(OptionsResolver $resolver)
318324

319325
return '';
320326
});
327+
$resolver->setDeprecated('html5', function (Options $options, $html5) {
328+
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));
331+
}
321332

322-
$resolver->setAllowedTypes('input_format', 'string');
333+
return '';
334+
});
323335
}
324336

325337
/**

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,16 @@ public function configureOptions(OptionsResolver $resolver)
306306
$resolver->setAllowedTypes('years', 'array');
307307
$resolver->setAllowedTypes('months', 'array');
308308
$resolver->setAllowedTypes('days', 'array');
309-
310309
$resolver->setAllowedTypes('input_format', 'string');
310+
311+
$resolver->setDeprecated('html5', function (Options $options, $html5) {
312+
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));
315+
}
316+
317+
return '';
318+
});
311319
}
312320

313321
/**

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-
DateTimeType, IntegerType, TimezoneType
48+
BirthdayType, DateTimeType, DateType, IntegerType, TimezoneType
4949
5050
Service form types
5151
------------------

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ public function testDontPassHtml5TypeIfHtml5NotAllowed()
470470
$this->assertArrayNotHasKey('type', $view->vars);
471471
}
472472

473+
/**
474+
* @group legacy
475+
*/
473476
public function testDontPassHtml5TypeIfNotHtml5Format()
474477
{
475478
$view = $this->factory->create(static::TESTED_TYPE, null, [

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function testSubmitFromSingleTextDateTimeWithCustomFormat()
7676
'widget' => 'single_text',
7777
'input' => 'datetime',
7878
'format' => 'yyyy',
79+
'html5' => false,
7980
]);
8081

8182
$form->submit('2010');
@@ -93,6 +94,7 @@ public function testSubmitFromSingleTextDateTime()
9394

9495
$form = $this->factory->create(static::TESTED_TYPE, null, [
9596
'format' => \IntlDateFormatter::MEDIUM,
97+
'html5' => false,
9698
'model_timezone' => 'UTC',
9799
'view_timezone' => 'UTC',
98100
'widget' => 'single_text',
@@ -114,6 +116,7 @@ public function testSubmitFromSingleTextDateTimeImmutable()
114116

115117
$form = $this->factory->create(static::TESTED_TYPE, null, [
116118
'format' => \IntlDateFormatter::MEDIUM,
119+
'html5' => false,
117120
'model_timezone' => 'UTC',
118121
'view_timezone' => 'UTC',
119122
'widget' => 'single_text',
@@ -136,6 +139,7 @@ public function testSubmitFromSingleTextString()
136139

137140
$form = $this->factory->create(static::TESTED_TYPE, null, [
138141
'format' => \IntlDateFormatter::MEDIUM,
142+
'html5' => false,
139143
'model_timezone' => 'UTC',
140144
'view_timezone' => 'UTC',
141145
'widget' => 'single_text',
@@ -157,6 +161,7 @@ public function testSubmitFromSingleTextTimestamp()
157161

158162
$form = $this->factory->create(static::TESTED_TYPE, null, [
159163
'format' => \IntlDateFormatter::MEDIUM,
164+
'html5' => false,
160165
'model_timezone' => 'UTC',
161166
'view_timezone' => 'UTC',
162167
'widget' => 'single_text',
@@ -180,6 +185,7 @@ public function testSubmitFromSingleTextRaw()
180185

181186
$form = $this->factory->create(static::TESTED_TYPE, null, [
182187
'format' => \IntlDateFormatter::MEDIUM,
188+
'html5' => false,
183189
'model_timezone' => 'UTC',
184190
'view_timezone' => 'UTC',
185191
'widget' => 'single_text',
@@ -270,6 +276,7 @@ public function testSubmitFromInputDateTimeDifferentPattern()
270276
'model_timezone' => 'UTC',
271277
'view_timezone' => 'UTC',
272278
'format' => 'MM*yyyy*dd',
279+
'html5' => false,
273280
'widget' => 'single_text',
274281
'input' => 'datetime',
275282
]);
@@ -286,6 +293,7 @@ public function testSubmitFromInputStringDifferentPattern()
286293
'model_timezone' => 'UTC',
287294
'view_timezone' => 'UTC',
288295
'format' => 'MM*yyyy*dd',
296+
'html5' => false,
289297
'widget' => 'single_text',
290298
'input' => 'string',
291299
]);
@@ -302,6 +310,7 @@ public function testSubmitFromInputTimestampDifferentPattern()
302310
'model_timezone' => 'UTC',
303311
'view_timezone' => 'UTC',
304312
'format' => 'MM*yyyy*dd',
313+
'html5' => false,
305314
'widget' => 'single_text',
306315
'input' => 'timestamp',
307316
]);
@@ -320,6 +329,7 @@ public function testSubmitFromInputRawDifferentPattern()
320329
'model_timezone' => 'UTC',
321330
'view_timezone' => 'UTC',
322331
'format' => 'MM*yyyy*dd',
332+
'html5' => false,
323333
'widget' => 'single_text',
324334
'input' => 'array',
325335
]);
@@ -368,6 +378,7 @@ public function testThrowExceptionIfFormatIsNoPattern()
368378
{
369379
$this->factory->create(static::TESTED_TYPE, null, [
370380
'format' => '0',
381+
'html5' => false,
371382
'widget' => 'single_text',
372383
'input' => 'string',
373384
]);
@@ -394,6 +405,7 @@ public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWid
394405
$this->factory->create(static::TESTED_TYPE, null, [
395406
'widget' => 'single_text',
396407
'format' => 'wrong',
408+
'html5' => false,
397409
]);
398410
}
399411

@@ -456,6 +468,7 @@ public function testSetDataWithNegativeTimezoneOffsetStringInput()
456468

457469
$form = $this->factory->create(static::TESTED_TYPE, null, [
458470
'format' => \IntlDateFormatter::MEDIUM,
471+
'html5' => false,
459472
'model_timezone' => 'UTC',
460473
'view_timezone' => 'America/New_York',
461474
'input' => 'string',
@@ -478,6 +491,7 @@ public function testSetDataWithNegativeTimezoneOffsetDateTimeInput()
478491

479492
$form = $this->factory->create(static::TESTED_TYPE, null, [
480493
'format' => \IntlDateFormatter::MEDIUM,
494+
'html5' => false,
481495
'model_timezone' => 'UTC',
482496
'view_timezone' => 'America/New_York',
483497
'input' => 'datetime',
@@ -856,6 +870,7 @@ public function testDontPassHtml5TypeIfNotHtml5Format()
856870
$view = $this->factory->create(static::TESTED_TYPE, null, [
857871
'widget' => 'single_text',
858872
'format' => \IntlDateFormatter::MEDIUM,
873+
'html5' => false,
859874
])
860875
->createView();
861876

0 commit comments

Comments
 (0)
0