Basically you'd wanna be using the FormElementManager
.
// Config array
'form_elements' => [
'factories' => [
'My\Cool\Fieldset' => 'My\Cool\FieldsetFactory'
]
]
And then you have anormal factory-class
class FieldsetFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $sl)
{
$realServiceLocator = $sl->getServiceLocator();
$entityManager = realServiceLocator->get('Doctrine\ORM\EntityManager');
return new \My\Cool\Fieldset($entityManager);
}
}
That would be the most proper way to do it.