Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4682c3

Browse files
feature #28721 [Form] deprecate some options for single_text widgets (xabbuh)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] deprecate some options for single_text 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 | Commits ------- 89ff331 deprecate some options for single_text widgets
2 parents 57f3cbb + 89ff331 commit f4682c3

File tree

7 files changed

+44
-3
lines changed

7 files changed

+44
-3
lines changed

UPGRADE-4.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Config
2020

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

23+
Form
24+
----
25+
26+
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
27+
set to `single_text` is deprecated.
28+
2329
FrameworkBundle
2430
---------------
2531

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Finder
7878
Form
7979
----
8080

81+
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
82+
set to `single_text` is not supported anymore.
8183
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static
8284
`getExtendedTypes()` method which must return an iterable of extended types.
8385

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,9 @@ public function testDateTimeWithWidgetSingleText()
16851685
);
16861686
}
16871687

1688+
/**
1689+
* @group legacy
1690+
*/
16881691
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
16891692
{
16901693
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
4.3.0
55
-----
66

7+
* deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget`
8+
option is set to `single_text`
79
* added `block_prefix` option to `BaseType`.
810
* added `help_html` option to display the `help` text as HTML.
911

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ public function configureOptions(OptionsResolver $resolver)
216216

217217
// Defaults to the value of "widget"
218218
$dateWidget = function (Options $options) {
219-
return $options['widget'];
219+
return 'single_text' === $options['widget'] ? null : $options['widget'];
220220
};
221221

222222
// Defaults to the value of "widget"
223223
$timeWidget = function (Options $options) {
224-
return $options['widget'];
224+
return 'single_text' === $options['widget'] ? null : $options['widget'];
225225
};
226226

227227
$resolver->setDefaults([
@@ -292,6 +292,31 @@ public function configureOptions(OptionsResolver $resolver)
292292
'text',
293293
'choice',
294294
]);
295+
296+
$resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
297+
if (null !== $dateFormat && 'single_text' === $options['widget']) {
298+
return sprintf('Using the "date_format" option of %s when the "widget" option is set to "single_text" is deprecated since Symfony 4.3 and will lead to an exception in 5.0.', self::class);
299+
//throw new LogicException(sprintf('Cannot use the "date_format" option of the %s when the "widget" option is set to "single_text".', self::class));
300+
}
301+
302+
return '';
303+
});
304+
$resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) {
305+
if (null !== $dateWidget && 'single_text' === $options['widget']) {
306+
return sprintf('Using the "date_widget" option of %s when the "widget" option is set to "single_text" is deprecated since Symfony 4.3 and will lead to an exception in 5.0.', self::class);
307+
//throw new LogicException(sprintf('Cannot use the "date_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
308+
}
309+
310+
return '';
311+
});
312+
$resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) {
313+
if (null !== $timeWidget && 'single_text' === $options['widget']) {
314+
return sprintf('Using the "time_widget" option of %s when the "widget" option is set to "single_text" is deprecated since Symfony 4.3 and will lead to an exception in 5.0.', self::class);
315+
//throw new LogicException(sprintf('Cannot use the "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
316+
}
317+
318+
return '';
319+
});
295320
}
296321

297322
/**

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,9 @@ public function testDateTimeWithWidgetSingleText()
15061506
);
15071507
}
15081508

1509+
/**
1510+
* @group legacy
1511+
*/
15091512
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
15101513
{
15111514
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [

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

0 commit comments

Comments
 (0)