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

wants to merge 2 commits into

4 participants


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
'type' => 'Element\Class'
'options' => $someOptions

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


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.


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


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?

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

@weierophinney weierophinney added a commit that referenced this pull request May 22, 2013
@weierophinney weierophinney Merge branch 'feature/4400' into develop
Close #4400
Zend Framework member

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