@@ -42,6 +42,20 @@ public function __construct(ObjectManager $em, RouterInterface $router, $config)
42
42
43
43
public function buildForm (FormBuilderInterface $ builder , array $ options )
44
44
{
45
+ /* @var $em ObjectManager */
46
+ $ em = null ;
47
+
48
+ // custom object manager for this entity, override the default entity manager ?
49
+ if (isset ($ options ['object_manager ' ])) {
50
+ $ em = $ options ['object_manager ' ];
51
+ if (!$ em instanceof ObjectManager) {
52
+ throw new \Exception ('The entity manager \'em \' must be an ObjectManager instance ' );
53
+ }
54
+ } else {
55
+ // else, we use the default entity manager
56
+ $ em = $ this ->em ;
57
+ }
58
+
45
59
// add custom data transformer
46
60
if ($ options ['transformer ' ]) {
47
61
if (!is_string ($ options ['transformer ' ])) {
@@ -51,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
51
65
throw new \Exception ('Unable to load class: ' .$ options ['transformer ' ]);
52
66
}
53
67
54
- $ transformer = new $ options ['transformer ' ]($ this -> em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ]);
68
+ $ transformer = new $ options ['transformer ' ]($ em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ]);
55
69
56
70
if (!$ transformer instanceof DataTransformerInterface) {
57
71
throw new \Exception (sprintf ('The custom transformer %s must implement "Symfony\Component\Form\DataTransformerInterface" ' , get_class ($ transformer )));
@@ -67,8 +81,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
67
81
}
68
82
69
83
$ transformer = $ options ['multiple ' ]
70
- ? new EntitiesToPropertyTransformer ($ this -> em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ], $ newTagPrefix )
71
- : new EntityToPropertyTransformer ($ this -> em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ], $ newTagPrefix );
84
+ ? new EntitiesToPropertyTransformer ($ em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ], $ newTagPrefix )
85
+ : new EntityToPropertyTransformer ($ em , $ options ['class ' ], $ options ['text_property ' ], $ options ['primary_key ' ], $ newTagPrefix );
72
86
}
73
87
74
88
$ builder ->addViewTransformer ($ transformer , true );
0 commit comments