Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

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'.

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....

Contributor

noopable commented May 18, 2013

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.

Contributor

danizord commented May 19, 2013

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

Contributor

noopable commented May 19, 2013

@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?

Owner

weierophinney commented May 22, 2013

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.

@weierophinney weierophinney added a commit that referenced this pull request May 22, 2013

@weierophinney weierophinney Merge pull request #4400 from noopable/patch-FormElementManager-withP…
…arams

Ability to get an element with creation options from the FormElementManager
29661d3

@weierophinney weierophinney added a commit that referenced this pull request May 22, 2013

@weierophinney weierophinney Merge branch 'feature/4400' into develop
Close #4400
f9b8e02
Owner

weierophinney commented May 22, 2013

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

@noopable noopable deleted the noopable:patch-FormElementManager-withParams branch Dec 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment