Q:

ManyToMany relation between News and Users

I have an Entity called News which contains a ManyToMany relation with the User Entity. This means that an article can be written by multiple authors.
/**
* @ORM\ManyToMany(targetEntity="GW2\UserBundle\Entity\User")
*/
private $authors;

The problem is that I would like to add authors dynamically in the form I use to add News, but I don't know how to store the data, and keep the relation between my two Entities. The number of authors is not fixed, and not limited.
I did some research about the collection type and added it to my NewsType, but I don't really know how to use it.

Edit: Here is my current NewsType (without the authors collection):
<?php
namespace GW2\SiteBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class NewsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title', 'text', array('error_bubbling' => true))
            ->add('introduction', 'textarea', array('attr' => array('class' => 'input-block-level redactor_content'), 'error_bubbling' => true))
            ->add('content', 'textarea', array('attr' => array('class' => 'input-block-level redactor_content'), 'error_bubbling' => true))
            ->add('publication', 'checkbox', array('required' => false, 'error_bubbling' => true))
            ->add('categories', 'entity', array(
                'class' => 'GW2SiteBundle:Category',
                'property' => 'name',
                'required' => false,
                'multiple' => true
            ))
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'GW2\SiteBundle\Entity\News'
        ));
    }

    public function getName()
    {
        return 'gw2_sitebundle_newstype';
    }
}

A:

I finally fixed my problem by adding a collection with the FOSUB type, while specifying the allow_add and allow_delete options.
->add('authors', 'collection', array(
    'type'=> 'fos_user_username',
    'allow_add' => true,
    'allow_delete' => true
))

Then I added the adding-removing solution with JavaScript to dynamically add fields in the form (thanks to Thomas Potaire).

