title: Symfony 4 collection type transformer. How to elegantly display the values in a text field?
body: <p>I'm working with symfony 4. I have a ManyToMany relationship(surprisingly not that relevant to the question) featuring a junction table. Lets say entity A can have many entity B and vice versa. Lets also assume that A owns B.</p>
  <p>I have built a form that looks like this:</p>
  <pre><code>$builder
      -&gt;add('B', TextType::class, [
          'invalid_message' =&gt; 'Some invalid message',
          'attr' =&gt; [
              'class' =&gt; 'tags',
          ]
      ])
      -&gt;add('save', SubmitType::class);
  
  $builder-&gt;get('B')
      -&gt;addModelTransformer($this-&gt;transformer)
  ;
  </code></pre>
  <p>Next I have the transformer:</p>
  <pre><code>public function transform($bunchOfB_s)
  {
      // returns json_encode
  }
  
  
  public function reverseTransform($bunchOfB_s)
  {
      // json_decode and transform to B entity
  }
  </code></pre>
  <p>I couldn't find a decent solution as to NOT render each B separately.</p>
  <p>The problem is in the html itself. Currently it looks like this:</p>
  <pre><code>&lt;div class=&quot;form-group&quot;&gt;&lt;label for=&quot;admin_video_tags&quot; class=&quot;required&quot;&gt;Tags&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;admin_video_tags&quot; name=&quot;admin_video[tags]&quot; required=&quot;required&quot; class=&quot;tags form-control ui-autocomplete-input&quot; value=&quot;[{&amp;quot;name&amp;quot;:&amp;quot;tag_ 6&amp;quot;,&amp;quot;id&amp;quot;:47},{&amp;quot;name&amp;quot;:&amp;quot;tag_ 7&amp;quot;,&amp;quot;id&amp;quot;:48},{&amp;quot;name&amp;quot;:&amp;quot;tag_ 16&amp;quot;,&amp;quot;id&amp;quot;:57}]&quot; autocomplete=&quot;off&quot;&gt;&lt;/div&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/RDOce.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RDOce.jpg" alt="enter image description here" /></a></p>
  <p>I want to use an autocomplete via some jquery plugin or something. I don't need to do an ajax call since there are only about 15 total values for this field. I can simply pass them to the view when I render it.</p>
  <p>I can use javascript to clear the field.</p>
  <p>However, that doesn't strike me as an elegant solution. It's more of a hack.</p>
  <p>Ideally, I'm looking for something more elegant.</p>
  <p>Honestly not sure what. I'm hoping somebody who knows their way better around symfony 4 can lend a hand.</p>