Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Ability to get an element with creation options from the FormElementManager #4400

Conversation

noopable
Copy link
Contributor

@noopable noopable commented May 3, 2013

Now we can get an element from the FormElementManager with only name.

$element = $FormElementManager->get('element', 'foo');
echo $element->getName();// foo

It is inconvenient not to have the 2nd parameter, 'options'.

@vadexito
Copy link

would be also great to have the options parameter when we use
$form->add([
'type' => 'Element\Class'
'options' => $someOptions
]);

it seems also to be instantiated by the formelementmanager without the options parameter....

@noopable
Copy link
Contributor Author

Yes, it is available.
But I said about FormElementManager's capability.
Sometimes, the FormElementManager is a gateway to get a customized form with creationOptions. And this is AbstractPluginManager's normal behavior.

$form = $formManager->get('Application/Form/Contact', $someOptions);

And so, the first parameter of FormElementManager::get is the name representing an instance. If we want to use class type, set it to Invokable or set the serviceConfig or set the di alias .
Invokable enables us to create an instance in simple use.
And new FormAbstractServiceFactory enables us to create a form with the serviceConfig.
And the di enables us to compose the form elements by di configuration.

But now the FormElementManager drops options for invokale.This PR will fix it.

@danizord
Copy link
Contributor

@noopable That's why we have the Zend\Form\Factory.

@noopable
Copy link
Contributor Author

@danizord
Thanks.
Can you tell me why AbstractPluginManager::get accept the 2nd parameter as CreationOptions?
Why does the FormPluginManager drop creationOptions though we cannot set even a label through it?
Is it just because there is factory?

@weierophinney
Copy link
Member

Why does the FormPluginManager drop creationOptions though we cannot set even a label through it?

It doesn't, though. If you write a custom factory, you will get the options; they will also be passed to invokables. That said, I think your approach makes a lot of sense, considering that the constructor for all objects under Zend\Form use $name as the first argument.

@ghost ghost assigned weierophinney May 22, 2013
weierophinney added a commit that referenced this pull request May 22, 2013
…arams

Ability to get an element with creation options from the FormElementManager
weierophinney added a commit that referenced this pull request May 22, 2013
@weierophinney
Copy link
Member

Merged to develop for release with 2.3, as it's a minor behavior change.

@noopable noopable deleted the patch-FormElementManager-withParams branch December 13, 2013 13:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants