Skip to content

Commit e0a1294

Browse files
raziel057fabpot
authored andcommitted
[Form] Add flexibility for EntityType
1 parent c856a01 commit e0a1294

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
3030
*
3131
* This property should only be accessed through queryBuilder.
3232
*
33-
* @var QueryBuilder
33+
* @var QueryBuilder|null
3434
*/
3535
private $queryBuilder;
3636

@@ -68,7 +68,7 @@ public function __construct($queryBuilder, $manager = null, $class = null)
6868

6969
$queryBuilder = $queryBuilder($manager->getRepository($class));
7070

71-
if (!$queryBuilder instanceof QueryBuilder) {
71+
if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
7272
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
7373
}
7474
}
@@ -81,6 +81,10 @@ public function __construct($queryBuilder, $manager = null, $class = null)
8181
*/
8282
public function getEntities()
8383
{
84+
if (null === $this->queryBuilder) {
85+
return array();
86+
}
87+
8488
return $this->queryBuilder->getQuery()->execute();
8589
}
8690

@@ -89,6 +93,10 @@ public function getEntities()
8993
*/
9094
public function getEntitiesByIds($identifier, array $values)
9195
{
96+
if (null === $this->queryBuilder) {
97+
return array();
98+
}
99+
92100
$qb = clone ($this->queryBuilder);
93101
$alias = current($qb->getRootAliases());
94102
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
212212

213213
$field->submit('2');
214214
}
215+
216+
public function testConfigureQueryBuilderWithClosureReturningNull()
217+
{
218+
$field = $this->factory->createNamed('name', 'entity', null, array(
219+
'em' => 'default',
220+
'class' => self::SINGLE_IDENT_CLASS,
221+
'query_builder' => function () {
222+
return null;
223+
},
224+
));
225+
226+
$this->assertEquals(array(), $field->createView()->vars['choices']);
227+
}
215228

216229
public function testSetDataSingleNull()
217230
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy