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 showing red image for true fields #3420

Closed AntonioCS closed 9 years ago

AntonioCS commented 9 years ago

I have set a field to by doing:

$listMapper
    ->add('uniqueModeId')
    ->add('focPaint', 'boolean')

In the database the field focPaint is set to 1 (and is of type tinyint which translates to boolean in doctrine)

This is what I am seeing in the list page: sonta_wront_display

This is what I have in the database: table_contents

The ids are the same (believe me) and as you can see the FocPaint field is set to 1 so I should see the green image.

core23 commented 9 years ago

Can you show your doctrine mapping file?

AntonioCS commented 9 years ago

Here is the relevant part of the entity

/**
     * @var boolean
     *
     * @ORM\Column(name="foc_pait", type="boolean", nullable=false)
     */
    private $focPait;

Hope this is enough if not I will paste any other part you might need

pulzarraider commented 9 years ago

@AntonioCS do you have some custom template defined in your config.yml for boolean field? The default value should be 'SonataAdminBundle:CRUD:list_boolean.html.twig'.

I have tested the current dev-master of SonataAdminBundle and SonataDoctrineORMAdminBundle. Which versions do you use?

AntonioCS commented 9 years ago

I do not have any custom template for any types. I just started this project so I don't have much in it. This is my composer file:

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~4.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "friendsofsymfony/user-bundle": "~1.3",
    "sonata-project/doctrine-orm-admin-bundle": "^2.3",
    "sonata-project/user-bundle": "^2.2",
    "sonata-project/easy-extends-bundle": "^2.1",
    "sonata-project/admin-bundle": "~2.3",
    "sonata-project/media-bundle": "~2.3",
    "sonata-project/notification-bundle": "~2.3",
    "sonata-project/seo-bundle": "~1.1",
    "knplabs/knp-menu-bundle": "~1.1",
    "doctrine/doctrine-fixtures-bundle": "2.2.*"
},
"require-dev": {
    "sensio/generator-bundle": "~2.3"
},
pulzarraider commented 9 years ago

@AntonioCS can you please do some debugging to help us find the problem? Please start in the file your-project/vendor/sonata-project/admin-bundle/Resources/views/CRUD/list_boolean.html.twig and write in the field block: {{ dump(value) }}.

After refreshing the page, you sholud see bool(true) in every column if your value 1 is correctly transformed into boolean true.

AntonioCS commented 9 years ago

Well there is something wrong with the value because I am only seeing null.

Also, something I noticed, all the other fields have their title clickable, the focPaint is the only one (besides the actions) that is not clickable.

I might have made a mapping error somewhere but I am just not seeing it.

AntonioCS commented 9 years ago

So to just make sure doctrine was returning the correct data I did the following:

$repo = $this->getDoctrine()->getManager()->getRepository('MyBundle:MyEntity');
var_dump($repo->findBy([]));

I got the following results:

array (size=129)
  0 => 
    object(MyBundle\Entity\MyEntity)[564]
      private 'uniqueModeId' => string 'B9S...........' (length=14)
      private 'focPait' => boolean true
     <-- More fields --- >
  1 => 
    object(MyBundle\Entity\MyEntity)[567]
      private 'uniqueModeId' => string 'B9S...............' (length=14)
      private 'focPait' => boolean true
     <-- More fields --- >
<-- More items --->

As you can see doctrine is turning that field into a boolean. So, I think, we can exclude some doctrine mess up.

AntonioCS commented 9 years ago

There seem to be nothing wrong with the boolean field. I just turned another field into a boolean and it is showing the yes icon.

There does seem to be something wrong with the mapping. Don't know what exaclty but I guess this issue can be closed as this is not a boolean specific issue. (sorry about that and I will close it if nobody objects)