From c1f3c7e0a9e7b825189ae6639dae1bd0fe8d6974 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 27 Jun 2025 17:11:57 +0200 Subject: [PATCH] [Form] Change `default_protocol` default value to `null` in `UrlType` --- UPGRADE-8.0.md | 24 +++++++++++++++++++ src/Symfony/Component/Form/CHANGELOG.md | 5 ++++ .../Form/Extension/Core/Type/UrlType.php | 6 +---- .../Tests/Extension/Core/Type/UrlTypeTest.php | 19 +-------------- .../Type/UrlTypeValidatorExtensionTest.php | 2 +- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/UPGRADE-8.0.md b/UPGRADE-8.0.md index 80948b9422e55..7e50e26a5296e 100644 --- a/UPGRADE-8.0.md +++ b/UPGRADE-8.0.md @@ -131,6 +131,30 @@ DoctrineBridge $type = $extractor->getType(Foo::class, 'property'); ``` +Form +---- + + * The `default_protocol` option in `UrlType` now defaults to `null` instead of `'http'` + + *Before* + ```php + // URLs without protocol were automatically prefixed with 'http://' + $builder->add('website', UrlType::class); + // Input: 'example.com' → Value: 'http://example.com' + ``` + + *After* + ```php + // URLs without protocol are now kept as-is + $builder->add('website', UrlType::class); + // Input: 'example.com' → Value: 'example.com' + + // To restore the previous behavior, explicitly set the option: + $builder->add('website', UrlType::class, [ + 'default_protocol' => 'http', + ]); + ``` + FrameworkBundle --------------- diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index b74d43e79d23f..11115f3c1b7dc 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + + * Change default value of `default_protocol` option in `UrlType` from `'http'` to `null` + 7.4 --- diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index fd6025729ae91..6e5d623f3c1e7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -39,11 +39,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'default_protocol' => static function (Options $options) { - 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.'); - - return 'http'; - }, + 'default_protocol' => null, 'invalid_message' => 'Please enter a valid URL.', ]); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php index a0d335647dd34..714e92f09517a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php @@ -11,30 +11,13 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; -use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait; use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; class UrlTypeTest extends TextTypeTest { - use ExpectUserDeprecationMessageTrait; - public const TESTED_TYPE = UrlType::class; - /** - * @group legacy - */ - public function testSubmitAddsDefaultProtocolIfNoneIsIncluded() - { - $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.'); - $form = $this->factory->create(static::TESTED_TYPE, 'name'); - - $form->submit('www.domain.com'); - - $this->assertSame('http://www.domain.com', $form->getData()); - $this->assertSame('http://www.domain.com', $form->getViewData()); - } - public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded() { $form = $this->factory->create(static::TESTED_TYPE, null, [ @@ -107,6 +90,6 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect protected function getTestOptions(): array { - return ['default_protocol' => 'http']; + return []; } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php index edb212cbd49eb..e6314a3c59a29 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php @@ -20,7 +20,7 @@ class UrlTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase protected function createForm(array $options = []) { - return $this->factory->create(UrlType::class, null, $options + ['default_protocol' => 'http']); + return $this->factory->create(UrlType::class, null, $options); } public function testInvalidMessage() 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