-
Notifications
You must be signed in to change notification settings - Fork 87
Passing options to the element factory from the form factory #138
Comments
The problem is, that the Therefore, a fresh |
Here's a short example of what I'm trying to do: class MyForm extends Zend\Form\Form
{
public function init()
{
parent::init();
$this->add(['type' => MyFieldset::class, 'options' => ['foo' => 'My Option']]);
}
} class MyFieldset
{
private $foo;
public function __construct(string $foo)
{
$this->foo = $foo;
}
} class MyFieldsetFactory
{
public function __invoke(
ContainerInterface $container,
$requestedName,
array $options = null
) {
return new MyFieldset($options['foo']); // $options is an empty array
}
} The problem is that Before Service Manager 3, my factory implemented |
@MidnightDesign I've just run into something similar when creating custom elements and ended up at the same line of code you highlighted. The options are passed, but to setOptions() not the constructor. If you override |
I encountered this when upgrading from 2.8.1 to 2.11.0 Unless I am missing something, surely the solution is to pass the 'options' part of the $spec array into the factory call public function create($spec)
{
$spec = $this->validateSpecification($spec, __METHOD__);
$type = isset($spec['type']) ? $spec['type'] : Element::class;
$creationOptions = isset($spec['options']) ? $spec['options'] : [];
$element = $this->getFormElementManager()->get($type, $creationOptions);
if ($element instanceof FormInterface) {
return $this->configureForm($element, $spec);
} |
I'm looking to see if there's a particular reason why invocation of the getFormElementManager doesn't pass options if $spec contains options key and Factory waits until after object initializes to configure form. Other parts of the repo extending AbstractPluginManager pass options if available, seems only here this is omitted and prevents parts of my form construct or init to load. Adding
Original block: Line 117 in 4419eef
|
This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#18. |
Is it deliberate that there are no options passed from
Zend\Form\Factory#create()
to theFormElementManager
?I tried to add the
options
key from the$spec
array to theFormElementManager#get()
call, but that resulted inFactoryTest#testCanCreateWithConstructionLogicInOptions()
being broken.The text was updated successfully, but these errors were encountered: