Skip to content

Commit 3c81b62

Browse files
beberleistof
authored andcommitted
[Doctrine] Cleanup and move loader into its own method
1 parent 7646a5b commit 3c81b62

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntitiesToArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function transform($collection)
5252

5353
foreach ($collection as $entity) {
5454
// identify choices by their collection key
55-
$key = array_search($entity, $availableEntities);
55+
$key = array_search($entity, $availableEntities, true);
5656
$array[] = $key;
5757
}
5858
} else {

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class EntityType extends AbstractType
2424
{
25+
/**
26+
* @var ManagerRegistry
27+
*/
2528
protected $registry;
2629

2730
public function __construct(ManagerRegistry $registry)
@@ -58,11 +61,7 @@ public function getDefaultOptions(array $options)
5861
if (!isset($options['choice_list'])) {
5962
$manager = $this->registry->getManager($options['em']);
6063
if (isset($options['query_builder'])) {
61-
$options['loader'] = new ORMQueryBuilderLoader(
62-
$options['query_builder'],
63-
$manager,
64-
$options['class']
65-
);
64+
$options['loader'] = $this->getLoader($manager, $options);
6665
}
6766

6867
$defaultOptions['choice_list'] = new EntityChoiceList(
@@ -78,6 +77,22 @@ public function getDefaultOptions(array $options)
7877
return $defaultOptions;
7978
}
8079

80+
/**
81+
* Return the default loader object.
82+
*
83+
* @param ObjectManager
84+
* @param array $options
85+
* @return ORMQueryBuilderLoader
86+
*/
87+
protected function getLoader($manager, $options)
88+
{
89+
return new ORMQueryBuilderLoader(
90+
$options['query_builder'],
91+
$manager,
92+
$options['class']
93+
);
94+
}
95+
8196
public function getParent(array $options)
8297
{
8398
return 'choice';

0 commit comments

Comments
 (0)