2
votes

I want to set up a multiselect tags in my sonata admin form like in the picturebelow :

http://i.stack.imgur.com/FUjRV.jpg

Here is the code of my entity :

    class Company{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(name="name", type="string", length=255)
     */
    protected $name;


    /**
     * @ORM\ManyToMany(targetEntity="City", cascade={"persist"})
     */
    protected  $city;




    /**
     * Constructor
     */
    public function __construct()
    {
        $this->city = new \Doctrine\Common\Collections\ArrayCollection();
    }

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


    /**
     * Add city
     *
     * @param \Company\AdminBundle\Entity\City $city
     * @return Company
     */
    public function addVille(\Company\AdminBundle\Entity\City $city)
    {
        $this->city[] = $city;

        return $this;
    }

    /**
     * Remove city
     *
     * @param \Company\AdminBundle\Entity\City $city
     */
    public function removeCity(\Company\AdminBundle\Entity\City $city)
    {
        $this->city->removeElement($city);
    }

    /**
     * Get city
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Company
     */
    public function setName($name)
    {
        $this->name= $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    public function __toString()
    {

        return (string) $this->name;
    }
}

So I want that the first select tag contains all the cities and in the second , I select any element I want.

how can I make this kind of type?

1

1 Answers

0
votes

Sonata admin will automatically give you multiselect for properly configured Many-to-many relationships. You just need to use a jquery multiselect plugin to make the standard more useable, like your picture above.

See: https://github.com/yanickrochon/jquery.uix.multiselect