deprecate some options for single_text widgets

This commit is contained in:
Christian Flothmann 2018-10-04 12:32:57 +02:00
parent 5aa0967f9f
commit 89ff331865
7 changed files with 44 additions and 3 deletions

View File

@ -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
---------------

View File

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

View File

@ -1602,6 +1602,9 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
);
}
/**
* @group legacy
*/
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [

View File

@ -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

View File

@ -216,12 +216,12 @@ class DateTimeType extends AbstractType
// 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([
@ -292,6 +292,31 @@ class DateTimeType extends AbstractType
'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 '';
});
}
/**

View File

@ -1506,6 +1506,9 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
);
}
/**
* @group legacy
*/
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [

View File

@ -45,7 +45,7 @@ class DebugCommandTest extends TestCase
Built-in form types (Symfony\Component\Form\Extension\Core\Type)
----------------------------------------------------------------
IntegerType, TimezoneType
DateTimeType, IntegerType, TimezoneType
Service form types
------------------