Open weierophinney opened 4 years ago
How do you configure FormElementManager
? Do you have a factory that injects it with configuration?
I did something similar here: https://github.com/mtymek/blast-input-filter - I configure validator, filter and input filter plugin managers in a similar manner as you do. Take a look - maybe it will give you some hints. Alternatively, maybe you would like to contribute to my component and add support for form elements?
Originally posted by @mtymek at https://github.com/zendframework/zend-expressive/issues/387#issuecomment-258445397
Like I said, I only have a special ConfigProvider
which reads the config file and adds it to the configuration in the /config/config.php
. i thought that all the configuration is passed to formElementManager and others. To fix this I added the lines I mentioned.
Your package looks like a better solution though I am missing hydrators and form elements. The name of the package seems a bit misleading when adding hydrators and form elements.
Originally posted by @RalfEggert at https://github.com/zendframework/zend-expressive/issues/387#issuecomment-258460379
So, basically you're missing a factory that does the code you put in config.php
;) By itself, FormElementManager
doesn't know that it should look for form_elements
config key.
My package doesn't have hydrators and form elements because I don't use them (well, I use hydrators but I keep them in main SM...). But I'll be happy to accept PR or even consider changing the package name to something more relevant afterwards.
Originally posted by @mtymek at https://github.com/zendframework/zend-expressive/issues/387#issuecomment-258549394
@RalfEggert for this i usually use Delegator Factories like
<?php
namespace My\Namespace\Form;
use Interop\Container\ContainerInterface;
use Zend\Form\FormElementManager\FormElementManagerV3Polyfill;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
class FormElementManagerDelegatorFactory implements DelegatorFactoryInterface
{
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
$formElementManager = $callback();
$config = $container->has('config') ? $container->get('config') : [];
$config = isset($config['form_elements']) ? $config['form_elements'] : [];
(new Config($config))->configureServiceManager($formElementManager);
return $formElementManager;
}
}
and in my ConfigProvider config
<?php
return [
'dependencies' => [
'delegators' => [
'HydratorManager' => [
My\Namespace\Hydrator\HydratorManagerDelegatorFactory::class,
],
'InputFilterManager' => [
My\Namespace\InputFilter\InputFilterManagerDelegatorFactory::class,
],
'FormElementManager' => [
My\Namespace\Form\FormElementManagerDelegatorFactory::class,
],
],
],
];
yes, class naming could be improved ;-)
Originally posted by @skors at https://github.com/zendframework/zend-expressive/issues/387#issuecomment-258964348
I have a little module that configures the
FormElementManager
like this:This config is loaded by a
ConfigProvider
class and loaded by theConfigManager
in the/config/config.php
file like this:When I want to access the
ProductFormInterface::class
from theFormElementManager
it is not found. I need to these lines to the/config/container.php
file to get this running.What am I doing wrong? I don't think this is a wanted behaviour. In my module I also have some validators, filters, hydrators and input filters as well. Currently, I need to add the configuration manually for every specialized service managers.
Originally posted by @RalfEggert at https://github.com/zendframework/zend-expressive/issues/387