Skip to content

Set default_protocol only on types that define it - #7890

Open
phcorp wants to merge 1 commit into
EasyCorp:5.xfrom
phcorp:fix_url_field_default_protocol
Open

phcorp wants to merge 1 commit into
EasyCorp:5.xfrom
phcorp:fix_url_field_default_protocol

Conversation

@phcorp

@phcorp phcorp commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

UrlConfigurator always sets the default_protocol form option. Only UrlType (and the types whose parent is UrlType) defines it, so a UrlField rendered with another form type fails when the form is built:

// keep the clickable URL on index/detail pages but use a plain text input in forms
UrlField::new('website')->setFormType(TextType::class);
// UndefinedOptionsException: The option "default_protocol" does not exist.

Fix

Before setting the option, the configurator asks the form registry whether the field's form type defines default_protocol (FormRegistryInterface::getType($type)->getOptionsResolver()->isDefined(...)). So:

  • UrlType behaves as before
  • types extending UrlType through getParent() keep receiving the option
  • other types (e.g. TextType) no longer get it

UrlConfigurator gets form.registry as a constructor argument in config/services.php.

Tests

tests/Unit/Field/UrlFieldTest.php:

  • testDefaultProtocolOptionIsNotSetWhenFormTypeDoesNotDefineIt() (TextType)
  • testDefaultProtocolOptionIsSetWhenFormTypeExtendsUrlType() (a test type whose parent is UrlType)
  • the existing default_protocol tests still pass with UrlType

Results:

  • make tests ARGS="tests/Unit/Field/UrlFieldTest.php": OK (52 tests)
  • make tests ARGS="tests/Unit/Field tests/Functional/Fields": OK
  • make tests-parallel: OK (3688 tests)
  • phpstan and php-cs-fixer: no errors

@phcorp
phcorp force-pushed the fix_url_field_default_protocol branch 2 times, most recently from 42f3d84 to f703ff3 Compare November 7, 2026 02:06
UrlConfigurator always set the 'default_protocol' form option, which only
UrlType (and the types extending it) defines. Rendering a UrlField with
another form type, e.g. UrlField::new('website')->setFormType(TextType::class)
to keep the URL rendering on index/detail pages but use a plain text input,
failed with an UndefinedOptionsException.

The configurator now asks the form registry whether the field's form type
defines the option before setting it, so types whose parent is UrlType
keep receiving it.
@phcorp
phcorp force-pushed the fix_url_field_default_protocol branch from f703ff3 to 742b886 Compare November 8, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant