Answer the question
In order to leave comments, you need to log in
How to force Zend\Form\Factory to create usable filters via FilterPluginManage when creating forms?
In the configuration file of the module, I registered my own filter to create it through the FilterPluginManage:
return [
// ...
'filters' => [
'invokables' => [
'myfilter' => Application\Filter\MyFilter::class,
]
]
];
$formElementManager = $this->getServiceLocator()->get('FormElementManager');
$factory = new Zend\Form\Factory($formElementManager);
Answer the question
In order to leave comments, you need to log in
This option works:
$filterManager = $this->getServiceLocator()->get('FilterManager');
$factory = new Zend\Form\Factory();
$factory->getInputFilterFactory()
->getDefaultFilterChain()
->setPluginManager($filterManager);
class Module implements Zend\ModuleManager\Feature\FilterProviderInterface
{
// ...
/**
* {@inheritDoc}
*/
public function getFilterConfig()
{
return [
'invokables' => [
'myfilter' => \Application\Filter\MyFilter::class,
],
];
}
}
If I were you, in debug mode, I would see if the FilterPluginManager picked up the config settings, maybe something is wrong with the config?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question