I use entity for form field type, and get my list of options for that dropdownbox like this, works like a charm.
$builder->add('parent', 'entity', array(
'label' => 'Välj en fastighet för skärmen ',
'class' => 'BizTVContainerManagementBundle:Container','property'=>'name',
'query_builder' => function(EntityRepository $er) use ($parentType, $company) {
return $er->createQueryBuilder('u')
->where('u.containerType = :type', 'u.company = :company')
->setParameters( array('type' => $parentType, 'company' => $company) )
->orderBy('u.name', 'ASC');
},
));
Now, how can I customize the display name to be something I code together, instead of just the
'property'=>'name
What I would ultimately want to do is to have the currently displayed string, coupled with another string. I actually want to get this entity's parent's name in there as well, something like:
option_name = $entity->getName() . ' (' . $entity->getParent()->getName() . ')' .
Would be an easy thing if i had built the form myself, flat php html, but since I don't like to do hundreds of dull hours, I like to use symfony2 these days =)
any input welcome...