Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[OptionsResolver] Deprecate defining nested options viasetDefault() usesetOptions() instead#59618
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
5aee060 to616e8fcCompareyceruto commentedJan 26, 2025
Psalm failure is a false positive. |
616e8fc to48d601fCompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
48d601f to042cdfeComparesetDefault() usesetNested() insteadsetDefault() usesetOptions() instead877a720 to0ad4b89Comparesrc/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
3ed6e2d tode64012CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
de64012 to1172bdaComparesrc/Symfony/Component/OptionsResolver/Debug/OptionsResolverIntrospector.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
1172bda tob0bb9a1Compareyceruto commentedFeb 20, 2025
Just fixing conflicts |
fabpot commentedFeb 26, 2025
Thank you@yceruto. |
ffdbc83 intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
…ebugCommand` (yceruto)This PR was merged into the 7.3 branch.Discussion----------[Form] Add support for displaying nested options in `DebugCommand`| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues | -| License | MITAddressing#59618 (comment)```bash$ bin/console debug:form FooType baz --format=json```being `baz` a nested option of the `FooType`, output example in JSON format:```json{ "required": false, "default": [], "is_lazy": false, "has_normalizer": false, "has_nested_options": true, "nested_options": { "foo": { "required": true, "default": true, "is_lazy": false, "has_normalizer": false, "has_nested_options": false }, "bar": { "required": false, "default": true, "is_lazy": false, "has_normalizer": false, "has_nested_options": false } }}```The new additions here are the `has_nested_options` and `nested_options` entries.Cheers!Commits-------2a6d2d4 Add support for displaying nested options in DebugCommand
…`setOptions` instead of `setDefault` (yceruto)This PR was merged into the 7.3 branch.Discussion----------[OptionsResolver] Update nested options examples to use `setOptions` instead of `setDefault`closes#20705PRsymfony/symfony#59618Commits-------159a150 Update nested options examples to use setOptions instead of setDefault
…finition via `setDefault()`, use `setOptions()` instead (yceruto)This PR was merged into the 8.0 branch.Discussion----------[OptionsResolver] Remove support for nested options definition via `setDefault()`, use `setOptions()` instead| Q | A| ------------- | ---| Branch? | 8.0| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues | -| License | MITRef:#59618Commits-------f1abd5c Remove support for nested options definition via `setDefault()`, use `setOptions()` instead
Uh oh!
There was an error while loading.Please reload this page.
this removes unnecessary limitations that I hadn't considered when introducing nested options feature in#27291.
1. Allow defining default values for nested options
Imagine you want to define the following nested option in a generic form type:
then, I'd like to define a concrete type with a default value for it.
this might seem unexpected, but the fact is that the nested definition for
foooption inConcreteTypeis gone. As a result, when resolved, thefoooption will have a default value (['bar' => 23]) but without any constraints, allowing end users any value/type to be passed through this option forConcreteTypeinstancesFor example, passing
['foo' => false]as options forConcreteTypewould be allowed, instead of requiring an array wherebarexpects an integer value.2. Allow defining lazy default for nested options
the same problem would occur with a lazy default for a nested definition:
the issue here is the same as in the previous example, meaning this new default essentially overrides/removes the original nested definition
the two features mentioned earlier are now supported by introducing a new method
setOptions(), which separates the nested definition from its default value (whether direct or lazy). Additionally this PR deprecates the practice of defining nested options usingsetDefault()methodthis also enables the ability to set default values for prototyped options, which wasn't possible before. For example:
cheers!