title: Symfony2 form collection -
body: <p>I am building a gallery of images which must allow for tagging each image with keywords. To handle the tags, I'm using FPN/TagBundle (<a href="https://github.com/FabienPennequin/FPNTagBundle" rel="nofollow">https://github.com/FabienPennequin/FPNTagBundle</a>).</p>
  
  <p>I've already built the form, using the following:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>// UserAlbumImageType.php
  
  ...
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('description', null, array('label' =&gt; 'Description'))
          //TODO: add tags
          -&gt;add('tags', null, array(
              'label' =&gt; 'Tags',
              'mapped' =&gt; false,
              'required' =&gt; false,
              'attr' =&gt; array(
                  'class' =&gt; 'tags',
              ),
          ))
          -&gt;add('licenseType', 'entity', array(
              'label' =&gt; 'License',
              'class' =&gt; 'VoxCoreBundle:LicenseType',
          ))
          -&gt;add('privacyType', null, array('label' =&gt; 'Privacy'))
          ;
  }$builder
                  -&gt;add('images', 'collection', array(
                      'type' =&gt; new UserAlbumImageType(),
                      'label' =&gt; false,
                  ))
              ;
              break;
  ...
  
  // UserAlbumType.php
  
  ...
  $builder
      -&gt;add('images', 'collection', array(
          'type' =&gt; new UserAlbumImageType(),
          'label' =&gt; false,
      ))
      ;
      break;
  ...
  </code></pre>
  
  <p>As you can see, the tags property is NOT mapped. This is because I don't want to write the tags into a field in the database, but instead persist them to a central tag table. And that's where the problem lies.</p>
  
  <p>When the form is submitted, I'm simply calling <code>$em->persist($userAlbum)</code> which then persists changes to the <code>UserAlbumImage</code> objects in the collection. At this time, I'd like to grab the tags that were submitted via the form, and set them using the tag manager. I'm unsure where to handle this. In a Doctrine postPersist listener? If so, I'll still need to save the tags to the entity at least temporarily, then parse them. Is there a better way?</p>