title: How to set a class attribute to a Symfony form input with an attribut from entity linked
body: <p>I have in my form a "beds" attribute, an entity linked to another "bedroom".
  I would like for each input to add a class with the id of the linked entity "bedroom".</p>
  
  <pre><code>$form-&gt;add('beds', EntityType::class, array(
      'class' =&gt; 'DamiasResaBundle:Bed',
      'query_builder' =&gt; function (EntityRepository $er) {
          return $er-&gt;createQueryBuilder('b')
                    -&gt;orderBy('b.id', 'ASC');
      },
      'choice_label' =&gt; 'id',
      'label' =&gt; 'lits ',
      'multiple' =&gt; true,
      'expanded' =&gt;true,
      'attr' =&gt; array(
          'class' =&gt; function ($bed) {
              return $bed-&gt;getBedroom()-&gt;getId();
          }
       ),
   ))
  </code></pre>
  
  <p>I have two problems:</p>
  
  <ol>
  <li>'attr' => array('class'=>'test) return a class attribut in the div  containing the input, not a class attribut in the input.</li>
  <li>This previous code does not work and returns:</li>
  </ol>
  
  <blockquote>
    <p>An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Closure could not be converted to string") in form_div_layout.html.twig at line 358. </p>
  </blockquote>
  
  <p>Thank you for your help</p>