EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.05k stars 1.02k forks source link

Boolean field #667

Closed LogansUA closed 8 years ago

LogansUA commented 8 years ago

Hello.

I'm just installed this awesone bundle, and do some research.

So i found kinda bud. I have configured User entity in AppBundle\Entity\User:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
 * Class User
 *
 * @author Oleg Kachinsky <logansoleg@gmail.com>
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
 * @ORM\Table(name="users")
 *
 * @Gedmo\Loggable
 */
class User extends BaseUser
{
    use TimestampableEntity;

    /**
     * @var int $id ID
     *
     * @ORM\Id
     * @ORM\Column(type="integer", options={"unsigned"=true})
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var bool $boolean Boolean
     *
     * @ORM\Column(type="boolean")
     */
    private $boolean = true;

    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();

        // By default all users are admins
        $this->roles = ['ROLE_ADMIN'];
    }

    /**
     * Get ID
     *
     * @return int ID
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get expires at
     *
     * @return \DateTime Expires at
     */
    public function getExpiresAt()
    {
        return $this->expiresAt;
    }

    /**
     * Get credentials expire at
     *
     * @return \DateTime Credentials expire at
     */
    public function getCredentialsExpireAt()
    {
        return $this->credentialsExpireAt;
    }

    /**
     * Get boolean
     *
     * @return boolean Boolean
     */
    public function isBoolean()
    {
        return $this->boolean;
    }

    /**
     * Set boolean
     *
     * @param boolean $boolean boolean
     *
     * @return $this
     */
    public function setBoolean($boolean)
    {
        $this->boolean = $boolean;

        return $this;
    }
}

(getExpiresAt() and getCredentialsExpireAt() for FosUserBundle to access Edit and Create actions)

And configured Bundle:

# EasyAdminBundle Configuration
easy_admin:
    site_name: 'Snowstorm project'
    entities:
        User:
            label: 'Users'
            class: AppBundle\Entity\User
            list:
                title: 'Snowstorm users'
                fields:
                    - { property: 'id',        label: 'ID' }
                    - { property: 'username',  label: 'Username' }
                    - { property: 'email',     label: 'Email' }
                    - { property: 'enabled',   label: 'Enabled', type: 'toggle' }
                    - { property: 'boolean' }
                    - { property: 'lastLogin', label: 'Last login' }
                    - { property: 'createdAt', label: 'Created At' }
                    - { property: 'updatedAt', label: 'Updated At' }

And here said that by default boolean fields turns in toggle field. But by default i get simple field like that: Boolean

I found the solution in #585 issue, by changing the type: in configuration to toggle.

Also i use that hack from #585 which proposed @javiereguiluz in Controller/AdminController.php on 73 line use

dump($this->entity['edit']['fields']); exit;

It both way i get "type" => "boolean"

So i'm not sure that is bug, or just documentation is outdated.

Thank you.

P.S. Sorry for my English :smile:

javiereguiluz commented 8 years ago

@LogansUA thank you very much for reporting this error and for your very detailed explanation. It was really easy to spot what was happening :)

Indeed there was a bug about boolean/toggle fields. It has been fixed in #669, so it will be available in the next stable release. Thanks again for your bug report!

LogansUA commented 8 years ago

@javiereguiluz thank you too for this amazing bundle, finally normal alternative to SonataAdminBundle.

javiereguiluz commented 8 years ago

@LogansUA thanks to you, for using it and for reporting issues.

By the way, let's not forget about SonataAdminBundle because EasyAdmin will always reject features for the most complex backends (we target "the 80% easiest backends"). So we need a more advanced alternative, such as Sonata.