title: Symfony3 CollectionType, Data returns as null
body: <p>I have little problem creating collectiontype with symfony..</p>
  
  <p>I have tried to follow multiple tutorial,like
  <a href="http://symfony.com/doc/current/cookbook/form/form_collections.html" rel="nofollow">http://symfony.com/doc/current/cookbook/form/form_collections.html</a> or
  <a href="http://toni.uebernickel.info/2012/03/15/an-example-of-symfony2-collectiontype-form-field-prototype.html" rel="nofollow">http://toni.uebernickel.info/2012/03/15/an-example-of-symfony2-collectiontype-form-field-prototype.html</a>..</p>
  
  <p>but always with same result.</p>
  
  <p><code>$tags = $form-&gt;get('tags')-&gt;getData();</code> returns null.</p>
  
  <p>I'm able to generate add/remove link and indexing is working aswell, but getting data into controller...</p>
  
  <p>Am I missing something important or doing something wrong? Hope someone can help me out or give tip(s). </p>
  
  <p>what I currently have</p>
  
  <p><strong>Task entity</strong></p>
  
  <pre><code> /**  
   * @ORM\OneToMany(targetEntity="Tag", mappedBy="task",
   cascade={"persist", "remove"})  
   * /  protected $tags;
  </code></pre>
  
  <p><strong>Tag entity</strong></p>
  
  <pre><code> /**  
   * @ORM\ManyToOne(targetEntity="Task", inversedBy="tags")  
   * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")  
   * / 
   protected $task;
  </code></pre>
  
  <p><strong>TaskType</strong></p>
  
  <pre><code>-&gt;add('tags', CollectionType::class, array(
  'entry_type' =&gt; TagType::class,
  'allow_add' =&gt; true,
  'allow_delete' =&gt; true,
  'prototype_name' =&gt; '__tag__name__',))
  </code></pre>
  
  <p><strong>TagType</strong></p>
  
  <pre><code>$builder-&gt;add('name', TextType::class, array()));
  </code></pre>
  
  <p><strong>Macro</strong></p>
  
  <pre><code>{% macro widget_prototype(widget, remove_text) %}
     {% if widget.vars.prototype is defined %}
        {% set form = widget.vars.prototype %}
        {% set name = widget.vars.prototype.vars.name %}
     {% else %}
        {% set form = widget %}
        {% set name = widget.vars.full_name %}
     {% endif %}
  
     &lt;div data-content="{{ name }}"&gt;
        &lt;a class="btn-remove" data-related="{{ name }}"&gt;{{ remove_text }}&lt;/a&gt;
         {{ form_widget(form) }}
     &lt;/div&gt;
  
  {% endmacro %}
  </code></pre>
  
  <p><strong>Twig</strong></p>
  
  <pre><code>&lt;div id="post_tags" data-prototype="{{ _self.widget_prototype(form.tags, 'Remove tag')|escape }}"&gt;
   {% for widget in form.tags.children %}
       {{ _self.widget_prototype(widget, 'Remove tag') }}
   {% endfor %}
  &lt;/div&gt;
  &lt;a class="btn-add" data-target="post_tags"&gt;Add tag&lt;/a&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>jQuery(function($) {
      $(document).on('click', '.btn-add[data-target]', function(event) {
          var collectionHolder = $('#' + $(this).attr('data-target'));
  
          if (!collectionHolder.attr('data-counter')) {
              collectionHolder.attr('data-counter', collectionHolder.children().length);
          }
  
          var prototype = collectionHolder.attr('data-prototype');
          var form = prototype.replace(/__tag__name__/g, collectionHolder.attr('data-counter'));
  
          collectionHolder.attr('data-counter', Number(collectionHolder.attr('data-counter')) + 1);
          collectionHolder.append(form);
  
          event &amp;&amp; event.preventDefault();
      });
  
      $(document).on('click', '.btn-remove[data-related]', function(event) {
          var name = $(this).attr('data-related');
          $('*[data-content="'+name+'"]').remove();
  
          event &amp;&amp; event.preventDefault();
      });
  });
  </code></pre>
  
  <p>and in <strong>Controller</strong></p>
  
  <pre><code>$form = $this-&gt;createForm(TaskType::class, $task);
  </code></pre>
  
  <p><strong>EDIT / UPDATE</strong></p>
  
  <p>Task Entity setters and getters for tags</p>
  
  <pre><code>public function __construct()
  {
     $this-&gt;tags = new \Doctrine\Common\Collections\ArrayCollection();
  }
  
  public function add(Tag $tag)
  {
     $this-&gt;tags[] = $tag;
     return $this;
  }
  
  public function removeTag(Tag $tag)
  {
     $this-&gt;tags-&gt;removeElement($tag);
  }
  
  public function getTags()
  {
     return $this-&gt;tags;
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>$task = new Task();
  $form = $this-&gt;createForm(TaskType::class, $task);
  $form-&gt;handleRequest($request);
  if($form-&gt;isValid()){
      $tags = $form-&gt;get('tags')-&gt;getData();
  
       foreach($tags as $tag){
           //Here var_dump, echo, print, array_push etc tricks = empty
       }
  
       //Also without foreach var_dump = empty
  }
  </code></pre>