Короче быстро наваял сие чудо:
class ChoicesCollectionToArrayTransformer implements DataTransformerInterface
{
private $choiceList;
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
}
public function transform($collection)
{
if (null === $collection) {
return array();
}
if (is_array($collection)) {
return $collection;
}
if (!$collection instanceof Collection) {
throw new TransformationFailedException('Expected a Doctrine\Common\Collections\Collection object.');
}
return $this->choiceList->getValuesForChoices($collection->toArray());
}
public function reverseTransform($array)
{
if ('' === $array || null === $array) {
$array = array();
} else {
$array = (array) $array;
}
$choices = $this->choiceList->getChoicesForValues($array);
if (count($choices) !== count($array)) {
throw new TransformationFailedException('Could not find all matching choices for the given values');
}
return new ArrayCollection($choices);
}
}
И использовал в UserType:
$skillsChoiceList = new ObjectChoiceList(
$this->skillManager->getAllSkills()->toArray(),
'name',
array(),
null,
'alias'
);
$builder ->add('skills', 'choice', array(
'choice_list' => $skillsChoiceList,
'multiple' => true
));
$builder->get('skills')->resetViewTransformers()->addViewTransformer(new ChoicesCollectionToArrayTransformer($skillsChoiceList));
Работает.