sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Boolean field isn't set correctly #5720

Closed Minirock closed 4 years ago

Minirock commented 5 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
# Put the result here.

Symfony packages

$ composer show --latest 'symfony/*'
sonata-project/admin-bundle              3.54.0 3.54.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.18.1 3.18.1 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.17.0 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.1  1.3.1  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.10.0 3.10.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdmin...
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library
sonata-project/user-bundle               4.5.0  4.5.0  Symfony SonataUserBundle

#### PHP version
$ php -v

PHP 7.3.5 (cli) (built: May  1 2019 13:17:17) ( ZTS MSVC15 (Visual C++ 2017) x64
 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies

Subject

I have an entity with a boolean field. If I create a record with the boolean set to false, then in the view list I can see "no" as expected, but in the form list I can see "yes"

This is happening when the boolean field is set with BooleanType in the Admin configureFormFields. But, if I use the CheckBoxType then all works fine.

So looks like this is only related to BooleanType.

jeroendk commented 5 years ago

You have to set the transform option to true, this transforms your boolean value to the YES/NO options in the BooleanType:

 $formMapper
    ->add('enabled', BooleanType::class, [
           'transform' => true
    ])
stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Minirock commented 4 years ago

@jeroendk solution worked

smilesrg commented 2 years ago

But BooleanType is not a good code. What's in author's mind to create constants like that for a boolean type?

    public const TYPE_YES = 1;

    public const TYPE_NO = 2;