Removed Closure support from group_by (PropertyPath strings only)
This commit is contained in:
parent
037933a2ec
commit
e6554d6d45
@ -160,17 +160,13 @@ class EntityChoiceList extends ArrayChoiceList
|
|||||||
$grouped = array();
|
$grouped = array();
|
||||||
|
|
||||||
foreach ($entities as $entity) {
|
foreach ($entities as $entity) {
|
||||||
if ($groupBy instanceof \Closure) {
|
// Get group name from property path
|
||||||
// Get group name from Closure
|
try {
|
||||||
$group = $groupBy($entity);
|
$path = new PropertyPath($groupBy);
|
||||||
} else {
|
$group = (string) $path->getValue($entity);
|
||||||
// Get group name from property path
|
} catch (UnexpectedTypeException $e) {
|
||||||
try {
|
// PropertyPath cannot traverse entity
|
||||||
$path = new PropertyPath($groupBy);
|
$group = null;
|
||||||
$group = (string) $path->getValue($entity);
|
|
||||||
} catch (UnexpectedTypeException $e) {
|
|
||||||
// PropertyPath cannot traverse entity
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($group)) {
|
if (empty($group)) {
|
||||||
|
@ -150,36 +150,4 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
'4' => 'Boo!'
|
'4' => 'Boo!'
|
||||||
), $choiceList->getChoices('choices'));
|
), $choiceList->getChoices('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupBySupportsClosure()
|
|
||||||
{
|
|
||||||
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
|
|
||||||
$item2 = new ItemGroupEntity(2, 'Bar', 'Group2');
|
|
||||||
$item3 = new ItemGroupEntity(3, 'Baz', null);
|
|
||||||
|
|
||||||
$this->em->persist($item1);
|
|
||||||
$this->em->persist($item2);
|
|
||||||
$this->em->persist($item3);
|
|
||||||
|
|
||||||
$choiceList = new EntityChoiceList(
|
|
||||||
$this->em,
|
|
||||||
self::ITEM_GROUP_CLASS,
|
|
||||||
'name',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
$item1,
|
|
||||||
$item2,
|
|
||||||
$item3,
|
|
||||||
),
|
|
||||||
function($entity) {
|
|
||||||
return $entity->group_name;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(array(
|
|
||||||
'Group1' => array(1 => 'Foo'),
|
|
||||||
'Group2' => array(2 => 'Bar'),
|
|
||||||
'3' => 'Baz'
|
|
||||||
), $choiceList->getChoices('choices'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user