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 01f65f4

Browse filesBrowse files
committed
deprecate custom formats with HTML5 widgets
1 parent 5aa0967 commit 01f65f4
Copy full SHA for 01f65f4

File tree

8 files changed

+48
-1
lines changed
Filter options

8 files changed

+48
-1
lines changed

‎UPGRADE-4.3.md

Copy file name to clipboardExpand all lines: UPGRADE-4.3.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Config
1313

1414
* Deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()`
1515

16+
Form
17+
----
18+
19+
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
20+
1621
FrameworkBundle
1722
---------------
1823

‎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
@@ -76,6 +76,7 @@ Finder
7676
Form
7777
----
7878

79+
* Removed support for using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled.
7980
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static
8081
`getExtendedTypes()` method which must return an iterable of extended types.
8182

‎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
* added `block_prefix` option to `BaseType`.
89

910
4.2.0

‎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
+13Lines changed: 13 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),
@@ -292,6 +296,15 @@ public function configureOptions(OptionsResolver $resolver)
292296
'text',
293297
'choice',
294298
]);
299+
300+
$resolver->setDeprecated('html5', function (Options $options, $html5) {
301+
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
302+
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);
303+
//throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
304+
}
305+
306+
return '';
307+
});
295308
}
296309

297310
/**

‎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-
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.