Fix "[Form] Add flexibility for EntityType"
This fixes commit e0a1294a44
.
This commit is contained in:
parent
a5a9385dbb
commit
eb08baa9fc
@ -30,7 +30,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
*
|
*
|
||||||
* This property should only be accessed through queryBuilder.
|
* This property should only be accessed through queryBuilder.
|
||||||
*
|
*
|
||||||
* @var QueryBuilder|null
|
* @var QueryBuilder
|
||||||
*/
|
*/
|
||||||
private $queryBuilder;
|
private $queryBuilder;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
|
|
||||||
$queryBuilder = $queryBuilder($manager->getRepository($class));
|
$queryBuilder = $queryBuilder($manager->getRepository($class));
|
||||||
|
|
||||||
if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
|
if (!$queryBuilder instanceof QueryBuilder) {
|
||||||
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,10 +81,6 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
*/
|
*/
|
||||||
public function getEntities()
|
public function getEntities()
|
||||||
{
|
{
|
||||||
if (null === $this->queryBuilder) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->queryBuilder->getQuery()->execute();
|
return $this->queryBuilder->getQuery()->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +89,6 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
*/
|
*/
|
||||||
public function getEntitiesByIds($identifier, array $values)
|
public function getEntitiesByIds($identifier, array $values)
|
||||||
{
|
{
|
||||||
if (null === $this->queryBuilder) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$qb = clone ($this->queryBuilder);
|
$qb = clone ($this->queryBuilder);
|
||||||
$alias = current($qb->getRootAliases());
|
$alias = current($qb->getRootAliases());
|
||||||
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
|
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
|
||||||
|
@ -30,7 +30,7 @@ class EntityType extends DoctrineType
|
|||||||
if (is_callable($queryBuilder)) {
|
if (is_callable($queryBuilder)) {
|
||||||
$queryBuilder = call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
|
$queryBuilder = call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
|
||||||
|
|
||||||
if (!$queryBuilder instanceof QueryBuilder) {
|
if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
|
||||||
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testConfigureQueryBuilderWithClosureReturningNull()
|
public function testConfigureQueryBuilderWithClosureReturningNull()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'entity', null, array(
|
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function () {
|
'query_builder' => function () {
|
||||||
|
Reference in New Issue
Block a user