remove deprecated date types options handling
This commit is contained in:
parent
2a631ecb83
commit
12ed0df223
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\PercentType;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormTypeExtensionInterface;
|
||||
use Symfony\Component\Form\Tests\AbstractLayoutTest;
|
||||
|
||||
abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
@ -1693,6 +1694,10 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
*/
|
||||
public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
|
||||
{
|
||||
if (method_exists(FormTypeExtensionInterface::class, 'getExtendedTypes')) {
|
||||
$this->markTestSkipped('The test requires symfony/form 4.x.');
|
||||
}
|
||||
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', '2011-02-03 04:05:06', [
|
||||
'input' => 'string',
|
||||
'date_widget' => 'choice',
|
||||
|
@ -4,6 +4,9 @@ CHANGELOG
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
* 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 `format` option of `DateType` and `DateTimeType` cannot be used when the `html5` option is enabled.
|
||||
* Using names for buttons that do not start with a letter, a digit, or an underscore throw an exception
|
||||
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons throw an exception.
|
||||
* removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Exception\LogicException;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
|
||||
@ -159,10 +160,6 @@ class DateTimeType extends AbstractType
|
||||
$dateOptions['input'] = $timeOptions['input'] = 'array';
|
||||
$dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;
|
||||
|
||||
if (isset($dateOptions['format']) && DateType::HTML5_FORMAT !== $dateOptions['format']) {
|
||||
$dateOptions['html5'] = false;
|
||||
}
|
||||
|
||||
$builder
|
||||
->addViewTransformer(new DataTransformerChain([
|
||||
new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts),
|
||||
@ -300,37 +297,33 @@ class DateTimeType extends AbstractType
|
||||
|
||||
$resolver->setAllowedTypes('input_format', 'string');
|
||||
|
||||
$resolver->setDeprecated('date_format', function (Options $options, $dateFormat) {
|
||||
$resolver->setNormalizer('date_format', function (Options $options, $dateFormat) {
|
||||
if (null !== $dateFormat && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
|
||||
return sprintf('Using the "date_format" option of %s with an HTML5 date widget 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 with an HTML5 date.', self::class));
|
||||
throw new LogicException(sprintf('Cannot use the "date_format" option of the %s with an HTML5 date.', self::class));
|
||||
}
|
||||
|
||||
return '';
|
||||
return $dateFormat;
|
||||
});
|
||||
$resolver->setDeprecated('date_widget', function (Options $options, $dateWidget) {
|
||||
$resolver->setNormalizer('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));
|
||||
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 '';
|
||||
return $dateWidget;
|
||||
});
|
||||
$resolver->setDeprecated('time_widget', function (Options $options, $timeWidget) {
|
||||
$resolver->setNormalizer('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));
|
||||
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 '';
|
||||
return $timeWidget;
|
||||
});
|
||||
$resolver->setDeprecated('html5', function (Options $options, $html5) {
|
||||
$resolver->setNormalizer('html5', function (Options $options, $html5) {
|
||||
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
|
||||
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);
|
||||
//throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
|
||||
throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
|
||||
}
|
||||
|
||||
return '';
|
||||
return $html5;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Exception\LogicException;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
|
||||
@ -308,13 +309,12 @@ class DateType extends AbstractType
|
||||
$resolver->setAllowedTypes('days', 'array');
|
||||
$resolver->setAllowedTypes('input_format', 'string');
|
||||
|
||||
$resolver->setDeprecated('html5', function (Options $options, $html5) {
|
||||
$resolver->setNormalizer('html5', function (Options $options, $html5) {
|
||||
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
|
||||
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);
|
||||
//throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
|
||||
throw new LogicException(sprintf('Cannot use the "format" option of %s when the "html5" option is disabled.', self::class));
|
||||
}
|
||||
|
||||
return '';
|
||||
return $html5;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1509,29 +1509,6 @@ 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', [
|
||||
'input' => 'string',
|
||||
'date_widget' => 'choice',
|
||||
'time_widget' => 'choice',
|
||||
'widget' => 'single_text',
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'UTC',
|
||||
]);
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), [],
|
||||
'/input
|
||||
[@type="datetime-local"]
|
||||
[@name="name"]
|
||||
[@value="2011-02-03T04:05:06"]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateChoice()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\DateType', date('Y').'-02-03', [
|
||||
|
@ -45,7 +45,7 @@ class DebugCommandTest extends TestCase
|
||||
Built-in form types (Symfony\Component\Form\Extension\Core\Type)
|
||||
----------------------------------------------------------------
|
||||
|
||||
BirthdayType, DateTimeType, DateType, IntegerType
|
||||
IntegerType
|
||||
|
||||
Service form types
|
||||
------------------
|
||||
|
@ -301,6 +301,7 @@ class DateTimeTypeTest extends BaseTypeTest
|
||||
public function testSubmitDifferentPattern()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
'html5' => false,
|
||||
'date_format' => 'MM*yyyy*dd',
|
||||
'date_widget' => 'single_text',
|
||||
'time_widget' => 'single_text',
|
||||
@ -470,20 +471,6 @@ class DateTimeTypeTest extends BaseTypeTest
|
||||
$this->assertArrayNotHasKey('type', $view->vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testDontPassHtml5TypeIfNotHtml5Format()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
'widget' => 'single_text',
|
||||
'format' => 'yyyy-MM-dd HH:mm',
|
||||
])
|
||||
->createView();
|
||||
|
||||
$this->assertArrayNotHasKey('type', $view->vars);
|
||||
}
|
||||
|
||||
public function testDontPassHtml5TypeIfNotSingleText()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
@ -497,6 +484,7 @@ class DateTimeTypeTest extends BaseTypeTest
|
||||
public function testSingleTextWidgetWithCustomNonHtml5Format()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime('2019-02-13 19:12:13'), [
|
||||
'html5' => false,
|
||||
'widget' => 'single_text',
|
||||
'date_format' => \IntlDateFormatter::SHORT,
|
||||
'format' => null,
|
||||
|
Reference in New Issue
Block a user