[DoctrineBridge] Fixed: Exception is thrown if the entity class is not known to Doctrine

This commit is contained in:
Bernhard Schussek 2012-12-06 11:23:39 +01:00
parent 889bd2ee62
commit 99321cbe24

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Form\Type; namespace Symfony\Bridge\Doctrine\Form\Type;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Form\Exception\FormException;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
@ -130,7 +131,17 @@ abstract class DoctrineType extends AbstractType
return $registry->getManager($em); return $registry->getManager($em);
} }
return $registry->getManagerForClass($options['class']); $em = $registry->getManagerForClass($options['class']);
if (null === $em) {
throw new FormException(sprintf(
'Class "%s" seems not to be a managed Doctrine entity. ' .
'Did you forget to map it?',
$options['class']
));
}
return $em;
}; };
$resolver->setDefaults(array( $resolver->setDefaults(array(