Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0823d38

Browse filesBrowse files
committed
deprecate custom formats with HTML5 widgets
1 parent 98bc3e7 commit 0823d38
Copy full SHA for 0823d38

File tree

8 files changed

+43
-1
lines changed
Filter options

8 files changed

+43
-1
lines changed

‎UPGRADE-4.3.md

Copy file name to clipboardExpand all lines: UPGRADE-4.3.md
+1Lines 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 the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
2728
set to `single_text` is deprecated.
2829

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+1Lines changed: 1 addition & 0 deletions
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 the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
8283
set to `single_text` is not supported anymore.
8384
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+1Lines 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+
* deprecated using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled
78
* deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget`
89
option is set to `single_text`
910
* added `block_prefix` option to `BaseType`.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
+12Lines changed: 12 additions & 0 deletions
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),
@@ -315,6 +319,14 @@ public function configureOptions(OptionsResolver $resolver)
315319
//throw new LogicException(sprintf('Cannot use the "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
316320
}
317321

322+
return '';
323+
});
324+
$resolver->setDeprecated('html5', function (Options $options, $html5) {
325+
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
326+
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);
327+
//throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
328+
}
329+
318330
return '';
319331
});
320332
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateType.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ public function configureOptions(OptionsResolver $resolver)
305305
$resolver->setAllowedTypes('years', 'array');
306306
$resolver->setAllowedTypes('months', 'array');
307307
$resolver->setAllowedTypes('days', 'array');
308+
309+
$resolver->setDeprecated('html5', function (Options $options, $html5) {
310+
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
311+
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);
312+
//throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
313+
}
314+
315+
return '';
316+
});
308317
}
309318

310319
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php
+3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
+15Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.