Skip to content

Commit 269e27f

Browse files
committed
feature #12251 [Bridge][Doctrine][Form] Add entity manager instance support for em option (egeloen)
This PR was merged into the 2.6-dev branch. Discussion ---------- [Bridge][Doctrine][Form] Add entity manager instance support for em option | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10157 | License | MIT | Doc PR | symfony/symfony-docs#4336 This PR allows to pass an explicit entity manager instance as em option. Commits ------- d84e3a8 [Bridge][Doctrine][Form] Add entity manager instance support for em option
2 parents 4fe8eda + d84e3a8 commit 269e27f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
143143
$emNormalizer = function (Options $options, $em) use ($registry) {
144144
/* @var ManagerRegistry $registry */
145145
if (null !== $em) {
146+
if ($em instanceof ObjectManager) {
147+
return $em;
148+
}
149+
146150
return $registry->getManager($em);
147151
}
148152

@@ -176,6 +180,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
176180
));
177181

178182
$resolver->setAllowedTypes(array(
183+
'em' => array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'),
179184
'loader' => array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'),
180185
));
181186
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public function testClassOptionIsRequired()
119119
$this->factory->createNamed('name', 'entity');
120120
}
121121

122+
/**
123+
* @expectedException Symfony\Component\Form\Exception\RuntimeException
124+
*/
125+
public function testInvalidClassOption()
126+
{
127+
$this->factory->createNamed('name', 'entity', null, array(
128+
'class' => 'foo',
129+
));
130+
}
131+
122132
public function testSetDataToUninitializedEntityWithNonRequired()
123133
{
124134
$entity1 = new SingleIntIdEntity(1, 'Foo');
@@ -758,6 +768,21 @@ public function testGetManagerForClassIfNoEm()
758768
));
759769
}
760770

771+
public function testExplicitEm()
772+
{
773+
$this->emRegistry->expects($this->never())
774+
->method('getManager');
775+
776+
$this->emRegistry->expects($this->never())
777+
->method('getManagerForClass');
778+
779+
$this->factory->createNamed('name', 'entity', null, array(
780+
'em' => $this->em,
781+
'class' => self::SINGLE_IDENT_CLASS,
782+
'property' => 'name',
783+
));
784+
}
785+
761786
protected function createRegistryMock($name, $em)
762787
{
763788
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');

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