symfony/symfony — pull request #5582 by nacmartin (2012-09-23 23:06:21+00:00)
Title: [Form] removed assertion that clashes with use of EntityChoiceList

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

Before the removed assertion, `$viewData` is assigned to `normToView($normData);` that can go through ChoiceToValueTransformer. This transformer returns a string no matter what, not an instance of the entity, so the assertion fails and the exception is thrown.

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php#L38

This Type makes this assertion crash:

```php
getFormFactory();
$refreshCountry = function($form, $preset = null) use ($factory) {
$form->add($factory->createNamed('country', 'entity', null, array(
'class' => 'Acme\DemoBundle\Entity\Country',
'data' => $preset,
)));
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshCountry) {
$form = $event->getForm();
$data = $event->getData();
if($data instanceof Product) {
$refreshCountry($form, $data->getCountry());
}
});
}

public function getName()
{
return 'product';
}

}
```

This code is only to reproduce the problem, it is useless as it is. An actual use case would be a chained selector city -> zone -> country