-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing options to the element factory from the form factory #18
Comments
The problem is, that the Therefore, a fresh Originally posted by @boesing at zendframework/zend-form#138 (comment) |
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 Originally posted by @MidnightDesign at zendframework/zend-form#138 (comment) |
@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 Originally posted by @kynx at zendframework/zend-form#138 (comment) |
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);
} Originally posted by @levofski at zendframework/zend-form#138 (comment) |
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: Originally posted by @daslani at zendframework/zend-form#138 (comment) |
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.Originally posted by @MidnightDesign at zendframework/zend-form#138
The text was updated successfully, but these errors were encountered: