Commit 25cd4e5
committed
feature symfony#58490 [Config] Allow using
This PR was merged into the 7.2 branch.
Discussion
----------
[Config] Allow using `defaultNull()` on `BooleanNodeDefinition`
| Q | A
| ------------- | ---
| Branch? | 7.2
| Bug fix? | yes-ish
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
After [this comment](https://github.com/symfony/symfony/pull/58095/files#r1740417930). Currently, `defaultNull()` on BooleanNode doesn't work well: the value always casts to `true`. This PR allows to make the node nullable by calling `defaultNull()` or `defaultValue(null)`.
Given the following configuration on a brand new project (with `composer require symfony/form symfony/csrf-protection`):
```yaml
framework:
csrf_protection: true
session: true
form:
csrf_protection:
enabled: null
```
Dumping `$config['form']['csrf_protection']['enabled']` reveals the `enabled` option is casted to `true` when set to `null` in the config. The following condition is **never** true:
https://github.com/symfony/symfony/blob/b61db2f7242c22e17d83807580b7fe9ed15d5cb0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L755
With this PR, the `enabled` option keeps the `null` value when defining the node as it already is in the code:
https://github.com/symfony/symfony/blob/b61db2f7242c22e17d83807580b7fe9ed15d5cb0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L214
Commits
-------
6aad690 [Config] Allow using `defaultNull()` on `BooleanNodeDefinition`defaultNull() on BooleanNodeDefinition (alexandre-daubois)File tree
5 files changed
+83
-3
lines changed- src/Symfony/Component/Config
- Definition
- Builder
- Tests/Definition
- Builder
5 files changed
+83
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
26 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
27 | 40 | | |
28 | 41 | | |
29 | 42 | | |
| |||
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
46 | 62 | | |
Lines changed: 27 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
29 | 56 | | |
30 | 57 | | |
31 | 58 | | |
| |||
60 | 87 | | |
61 | 88 | | |
62 | 89 | | |
63 | | - | |
64 | 90 | | |
65 | 91 | | |
66 | 92 | | |
| |||
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
28 | 52 | | |
29 | 53 | | |
30 | 54 | | |
| |||
0 commit comments