Skip to content

[Config] Allow using defaultNull() on BooleanNodeDefinition #58490

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Oct 8, 2024

Q A
Branch? 7.2
Bug fix? yes-ish
New feature? yes
Deprecations? no
Issues -
License MIT

After this comment. 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):

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:

if (null === $config['form']['csrf_protection']['enabled']) {

With this PR, the enabled option keeps the null value when defining the node as it already is in the code:

->booleanNode('enabled')->defaultNull()->end()

@nicolas-grekas
Copy link
Member

Do we need some changes in config builders, like done in #58428?

@alexandre-daubois
Copy link
Member Author

I don't think so, booleanNode() is already present in NodeBuilder and no change is required there to support nullable booleans.

@nicolas-grekas
Copy link
Member

Thank you @alexandre-daubois.

@nicolas-grekas nicolas-grekas merged commit 25cd4e5 into symfony:7.2 Oct 9, 2024
10 checks passed
@alexandre-daubois alexandre-daubois deleted the boolean-nullable branch October 9, 2024 14:29
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Oct 16, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

Add BC promise rules for constructors

As spotted in symfony/symfony#58490, following symfony/symfony#58490 (comment)

Commits
-------

72d416c Add BC promise rules for constructors
@fabpot fabpot mentioned this pull request Oct 27, 2024
@derrabus
Copy link
Member

derrabus commented Nov 3, 2024

This change apparently broke MonologBundle's test suite, see https://github.com/symfony/monolog-bundle/actions/runs/11651735613/job/32442060641#step:8:25 for instance. Can you please have a look, @alexandre-daubois?

@alexandre-daubois
Copy link
Member Author

Yes 👍

derrabus added a commit to symfony/monolog-bundle that referenced this pull request Nov 6, 2024
This PR was merged into the 3.x-dev branch.

Discussion
----------

Fix test with `symfony/config:^7.2`

Following symfony/symfony#58490 (comment). Until the Symfony PR, null wasn't supported in boolean nodes and defaulted to true.

Commits
-------

3fd3da1 Fix test with `symfony/config:^7.2`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants