Symfony use Tag-It as custom tagging field
===

I want to use the tag-it input to fill one entity's tags attribute. I make a custom field that use a tag-it input template. I used a DataTransformer to convert a list of tag entities to cvs string in order to fill the value attribute of the tag-it input and convert the cvs to a collection of entities (adding the tags not in database if needed). But the $tags parameter of the transform method is always null even if the article is tagged.

The tags attribute is defined this way:

    /**
     * @ORM\ManyToMany(targetEntity="Tamaplace\PressBundle\Entity\Tag")
     */
    private $tags;

The Tag entity:

    <?php

    /**
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Tamaplace\PressBundle\Entity\TagRepository")
     */
    class Tag
    {
        /**
         * @ORM\Column(name="id", type="string")
         * @ORM\Id
         */
        private $id;
    }

    ?>

And then the DataTransformer:

    <?php

    class TagsToCsvTransformer implements DataTransformerInterface
    {
        private $om;
    
        public function __construct(ObjectManager $om)
        {
            $this->om = $om;
        }
    
        public function transform($tags) // this $tag is always null
        {
            if (!$tags) {
               return '';
            }
    
            $values = array();
        
            foreach ($tags as &$tag) {
                $value[] = $tag->getId();
            }
        
            return implode(',', $values);
        }
    
        public function reverseTransform($csv)
        {
            $values = explode(',', $csv);
            $tags = new arrayCollection();
        
            $repository = $this->om->getRespository('TamaplacePressBundle:Tag');
        
            foreach ($values as &$value) {
                $tag = $repository->find($value);
            
                if (!$tag) {
                    $tag = new Tag($value);
                    $respository->persist($tag);
                }
            
                $tags->add($tag);
            }
        
            $respository->flush();
        
            return $tags;
        }
    }

    ?>