title: Symfony2 FormBuilder with Entity class
body: <p>I have a form that works well, there is just one issue with it and I'm hoping that I'll get an answer on how to do what I need to do.</p>
  
  <pre><code>&lt;?php
  
  namespace ADS\UserBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  use Symfony\Component\Security\Core\SecurityContext;
  
  class UserType extends AbstractType {
  private $type;
  public function __construct($type) {
      $this-&gt;type = $type;
  }
  
  public function buildForm(FormBuilderInterface $builder, array $options) {
      $builder
          -&gt;add('firstName', 'text', array('required' =&gt; true))
          -&gt;add('lastName', 'text', array('required' =&gt; true));
      $builder-&gt;add('email', 'email', array('required' =&gt; true));
      $builder-&gt;add('parentCompany', 'entity', array(
          'class' =&gt; 'ADSUserBundle:Company',
          'expanded' =&gt; false,
          'empty_value' =&gt; 'CHOOSE ONE',
          'required' =&gt; false,
          'property' =&gt; 'companyName'
      ))
      -&gt;add('enabled', 'choice', array('choices' =&gt; array('1' =&gt; 'Enabled', '0' =&gt; 'Disabled')))
      -&gt;add('roles', 'entity', array(
              'class' =&gt; 'ADSUserBundle:Roles',
              'required' =&gt; true,
              'property' =&gt; 'displayName',
          ));
  }
  
  public function setDefaultOptions(OptionsResolverInterface $resolver) {
      $resolver-&gt;setDefaults(array('data_class' =&gt; 'ADS\UserBundle\Entity\User'));
  }
  
  public function getName() { return 'ads_userbundle_user'; }
  }
  </code></pre>
  
  <p>I have this form, the portion I am looking at is the 'roles' portion...  Right now it created a multiple select box ( as I expect it to ), though the value is sequentially ie:  0,1,2,3,4...</p>
  
  <p>What I really need is to figure out how to take this entity, and make the <code>property</code> to be the <code>displayName</code> ( as it is now ) and get the value to be the corresponding <code>internalName</code>  This way it'll give me an array like:</p>
  
  <pre><code>array('ROLE_EXAMPLE' =&gt; 'EXAMPLE', 'ROLE_EXAMPLE1' =&gt; 'EXAMPLE1')
  </code></pre>
  
  <p>Any ideas how to accomplish this is greatly appreciated.</p>