[Form] Add flexibility for EntityType
This commit is contained in:
parent
c856a010a2
commit
e0a1294a44
@ -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
|
* @var QueryBuilder|null
|
||||||
*/
|
*/
|
||||||
private $queryBuilder;
|
private $queryBuilder;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
|
|
||||||
$queryBuilder = $queryBuilder($manager->getRepository($class));
|
$queryBuilder = $queryBuilder($manager->getRepository($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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,6 +81,10 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +93,10 @@ 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;
|
||||||
|
@ -212,6 +212,19 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$field->submit('2');
|
$field->submit('2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConfigureQueryBuilderWithClosureReturningNull()
|
||||||
|
{
|
||||||
|
$field = $this->factory->createNamed('name', 'entity', null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'query_builder' => function () {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals(array(), $field->createView()->vars['choices']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetDataSingleNull()
|
public function testSetDataSingleNull()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user