8000 [Form] deprecate some options for single_text widgets by xabbuh · Pull Request #28721 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] deprecate some options for single_text widgets #28721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-4.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Config

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

Form
----

* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
set to `single_text` is deprecated.

FrameworkBundle
---------------

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Finder
Form
----

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,9 @@ public function testDateTimeWithWidgetSingleText()
);
}

/**
* @group legacy
*/
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
4.3.0
-----

* deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget`
option is set to `single_text`
* added `block_prefix` option to `BaseType`.

4.2.0
Expand Down
29 changes: 27 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ public function configureOptions(OptionsResolver $resolver)

// Defaults to the value of "widget"
$dateWidget = function (Options $options) {
return $options['widget'];
return 'single_text' === $options['widget'] ? null : $options['widget'];
};

// Defaults to the value of "widget"
$timeWidget = function (Options $options) {
return $options['widget'];
return 'single_text' === $options['widget'] ? null : $options['widget'];
};

$resolver->setDefaults([
Expand Down Expand Up @@ -292,6 +292,31 @@ public function configureOptions(OptionsResolver $resolver)
'text',
'choice',
]);

$resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
if (null !== $dateFormat && 'single_text' === $options['widget']) {
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);
//throw new LogicException(sprintf('Cannot use the "date_format" option of the %s when the "widget" option is set to "single_text".', self::class));
}

return '';
});
$resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) {
if (null !== $dateWidget && 'single_text' === $options['widget']) {
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);
//throw new LogicException(sprintf('Cannot use the "date_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
}

return '';
});
$resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) {
if (null !== $timeWidget && 'single_text' === $options['widget']) {
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);
//throw new LogicException(sprintf('Cannot use the "time_widget" option of the %s when the "widget" option is set to "single_text".', self::class));
}

return '';
});
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,9 @@ public function testDateTimeWithWidgetSingleText()
);
}

/**
* @group legacy
*/
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testDebugDeprecatedDefaults()
Built-in form types (Symfony\Component\Form\Extension\Core\Type)
----------------------------------------------------------------

IntegerType, TimezoneType
DateTimeType, IntegerType, TimezoneType

Service form types
------------------
Expand Down
0