I want to reuse a Fieldset that implements InputFilterProviderInterface o it has the method getInputFilterSpecification where I can declare the specifications for all the elements in the fieldset.
public function getInputFilterSpecification()
{
return array(
'email' => array(
'filters' => $this->getTextFilters(),
'validators' => array(
$this->getUniqueObjectValidator()
...
The problem is that the getUniqueObjectValidator needs the Doctrine\ORM\EntityManager but it is not declared in the ServiceLocator for the InputFilter.
How do you think I can acces to the EntityManager in the inputFilter factories?
To do that, you need to inject the
DoctrineORM EntityManagerin yourfieldset. You could for example transfer ther$emfrom controller to form, and then from form to fieldset but this is a bad and ugly solution especialy when you have a complexe form with many fieldsets. A good solution is to take advantage from theZend\ServiceManager\ServiceLocator.Here is a proper way handle this :
First, you have to implement the
getFormElementConfig()function in your Module class. Something like this :Then make sure your fieldest calls the parent constructor like this :
And finaly instantiate the form via the
FormElementManager.:Please see these links for more details :