Skip to content

Commit 0cae29b

Browse files
feature #60922 [Form] Change UrlType default protocol (OskarStark)
This PR was merged into the 8.0 branch. Discussion ---------- [Form] Change `UrlType` default protocol | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | -- | License | MIT Commits ------- c1f3c7e [Form] Change `default_protocol` default value to `null` in `UrlType`
2 parents 48fc3dd + c1f3c7e commit 0cae29b

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

UPGRADE-8.0.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,30 @@ DoctrineBridge
134134
$type = $extractor->getType(Foo::class, 'property');
135135
```
136136

137+
Form
138+
----
139+
140+
* The `default_protocol` option in `UrlType` now defaults to `null` instead of `'http'`
141+
142+
*Before*
143+
```php
144+
// URLs without protocol were automatically prefixed with 'http://'
145+
$builder->add('website', UrlType::class);
146+
// Input: 'example.com' → Value: 'http://example.com'
147+
```
148+
149+
*After*
150+
```php
151+
// URLs without protocol are now kept as-is
152+
$builder->add('website', UrlType::class);
153+
// Input: 'example.com' → Value: 'example.com'
154+
155+
// To restore the previous behavior, explicitly set the option:
156+
$builder->add('website', UrlType::class, [
157+
'default_protocol' => 'http',
158+
]);
159+
```
160+
137161
FrameworkBundle
138162
---------------
139163

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+
8.0
5+
---
6+
7+
* Change default value of `default_protocol` option in `UrlType` from `'http'` to `null`
8+
49
7.4
510
---
611

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
3939
public function configureOptions(OptionsResolver $resolver): void
4040
{
4141
$resolver->setDefaults([
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-
},
42+
'default_protocol' => null,
4743
'invalid_message' => 'Please enter a valid URL.',
4844
]);
4945

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,13 @@
1111

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

14-
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1514
use Symfony\Component\Form\Extension\Core\Type\UrlType;
1615
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1716

1817
class UrlTypeTest extends TextTypeTest
1918
{
20-
use ExpectUserDeprecationMessageTrait;
21-
2219
public const TESTED_TYPE = UrlType::class;
2320

24-
/**
25-
* @group legacy
26-
*/
27-
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
28-
{
29-
$this->expectUserDeprecationMessage('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.');
30-
$form = $this->factory->create(static::TESTED_TYPE, 'name');
31-
32-
$form->submit('www.domain.com');
33-
34-
$this->assertSame('http://www.domain.com', $form->getData());
35-
$this->assertSame('http://www.domain.com', $form->getViewData());
36-
}
37-
3821
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
3922
{
4023
$form = $this->factory->create(static::TESTED_TYPE, null, [
@@ -107,6 +90,6 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
10790

10891
protected function getTestOptions(): array
10992
{
110-
return ['default_protocol' => 'http'];
93+
return [];
11194
}
11295
}

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 + ['default_protocol' => 'http']);
23+
return $this->factory->create(UrlType::class, null, $options);
2424
}
2525

2626
public function testInvalidMessage()

0 commit comments

Comments
 (0)
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