Skip to content

[Form] remove deprecated date types options handling #31777

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 1 commit into from
Jun 1, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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
Expand Down Expand Up @@ -1693,6 +1694,10 @@ public function testDateTimeWithWidgetSingleText()
*/
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',
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
33 changes: 13 additions & 20 deletions src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,10 +160,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$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),
Expand Down Expand Up @@ -300,37 +297,33 @@ public function configureOptions(OptionsResolver $resolver)

$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;
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -308,13 +309,12 @@ public function configureOptions(OptionsResolver $resolver)
$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;
});
}

Expand Down
23 changes: 0 additions & 23 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1509,29 +1509,6 @@ 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', [
'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', [
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)
----------------------------------------------------------------

BirthdayType, DateTimeType, DateType, IntegerType
IntegerType

Service form types
------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public function testSubmitStringSingleTextWithSeconds()
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',
Expand Down Expand Up @@ -470,20 +471,6 @@ public function testDontPassHtml5TypeIfHtml5NotAllowed()
$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, [
Expand All @@ -497,6 +484,7 @@ public function testDontPassHtml5TypeIfNotSingleText()
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,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy