8000 [Form] Deprecate not configuring the `default_protocol` option of the… · symfony/symfony@3ce498d · GitHub
[go: up one dir, main page]

Skip to content < 8000 div data-target="react-partial.reactRoot">

Commit 3ce498d

Browse files
committed
[Form] Deprecate not configuring the default_protocol option of the UrlType
1 parent 4e944be commit 3ce498d

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Deprecate not configuring the `default_protocol` option of the `UrlType`, it will default to `null` in 8.0
8+
49
7.0
510
---
611

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Form\FormBuilderInterface;
1717
use Symfony\Component\Form\FormInterface;
1818
use Symfony\Component\Form\FormView;
19+
use Symfony\Component\OptionsResolver\Options;
1920
use Symfony\Component\OptionsResolver\OptionsResolver;
2021

2122
class UrlType extends AbstractType
@@ -38,7 +39,11 @@ public function buildView(FormView $view, FormInterface $form, array $options):
3839
public function configureOptions(OptionsResolver $resolver): void
3940
{
4041
$resolver->setDefaults([
41-
'default_protocol' => 'http',
42+
'default_protocol' => static function (Options $options) {
43+
trigger_deprecation('symfony/form', '7.1', 'Not configuring the "default_protocol" option when using the UrlType is deprecated. It will default to "null" in 8.0.');
44+
45+
return 'http';
46+
},
4247
'invalid_message' => 'Please enter a valid URL.',
4348
]);
4449

src/Symfony/Component/Form/Tests/Extension/Core/Type/TextTypeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
2222

2323
public function testSubmitNullReturnsNullWithEmptyDataAsString()
2424
{
25-
$form = $this->factory->create(static::TESTED_TYPE, 'name', [
25+
$form = $this->factory->create(static::TESTED_TYPE, 'name', array_merge($this->getTestOptions(), [
2626
'empty_data' => '',
27-
]);
27+
]));
2828

2929
$form->submit(null);
3030
$this->assertSame('', $form->getData());
@@ -48,9 +48,9 @@ public static function provideZeros(): array
4848
*/
4949
public function testSetDataThroughParamsWithZero($data, $dataAsString)
5050
{
51-
$form = $this->factory->create(static::TESTED_TYPE, null, [
51+
$form = $this->factory->create(static::TESTED_TYPE, null, array_merge($this->getTestOptions(), [
5252
'data' => $data,
53-
]);
53+
]));
5454
$view = $form->createView();
5555

5656
$this->assertFalse($form->isEmpty());

src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1415
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1516

1617
class UrlTypeTest extends TextTypeTest
1718
{
19+
use ExpectDeprecationTrait;
20+
1821
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';
1922

23+
/**
24+
* @group legacy
25+
*/
2026
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
2127
{
28+
$this->expectDeprecation('Since symfony/form 7.1: Not configuring the "default_protocol" option when using the UrlType is deprecated. It will default to "null" in 8.0.');
2229
$form = $this->factory->create(static::TESTED_TYPE, 'name');
2330

2431
$form->submit('www.domain.com');
@@ -86,6 +93,7 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
8693
public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty')
8794
{
8895
$form = $this->factory->create(static::TESTED_TYPE, null, [
96+
'default_protocol' => 'http',
8997
'empty_data' => $emptyData,
9098
]);
9199
$form->submit(null);
@@ -95,4 +103,9 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
95103
$this->assertSame($expectedData, $form->getNormData());
96104
$this->assertSame($expectedData, $form->getData());
97105
}
106+
107+
protected function getTestOptions(): array
108+
{
109+
return ['default_protocol' => 'http'];
110+
}
98111
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UrlTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
2020

2121
protected function createForm(array $options = [])
2222
{
23-
return $this->factory->create(UrlType::class, null, $options);
23+
return $this->factory->create(UrlType::class, null, $options + ['default_protocol' => 'http']);
2424
}
2525

2626
public function testInvalidMessage()

src/Symfony/Component/Form/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.2",
20+
"symfony/deprecation-contracts": "^2.5|^3",
2021
"symfony/event-dispatcher": "^6.4|^7.0",
2122
"symfony/options-resolver": "^6.4|^7.0",
2223
"symfony/polyfill-ctype": "~1.8",

0 commit comments

Comments
 (0)
0