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

Pass options to factories as creation options #45

Closed
wants to merge 1 commit into from
Closed

Pass options to factories as creation options #45

wants to merge 1 commit into from

Conversation

fabiang
Copy link
Contributor

@fabiang fabiang commented Feb 22, 2016

Currently it's not possible to pass creation options to factories registered at the FormElementManager, when form elements are created by the form factory.

I use factories a lot for creating form elements and atm it's only possible to pass creation options with (inside a Zend\Form\Form instance):

$this->add($this->factory->getFormElementManager()->get('some_type', [
    'some_option' => 'some_value'
]));

Imho options from create() should also be passed as creation options to the factories.

This PR makes it possible to short-cut the above to the following:

$this->add([
    'type' => 'some_type',
    'options' => [
        'some_option' => 'some_value',
    ]
]);

The registered factory for type some_type then just need to pass the creation options to the form element.

@@ -16,6 +16,8 @@
use Zend\Form\Factory as FormFactory;
use Zend\ServiceManager\ServiceManager;
use Zend\Hydrator\HydratorPluginManager;
use Zend\Form\FormInterface;
use DateTime;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort use statement, D before Z

@weierophinney weierophinney added this to the 2.7.1 milestone Apr 7, 2016
@weierophinney weierophinney self-assigned this Apr 7, 2016
@weierophinney
Copy link
Member

I'm going to cherry-pick this to master for the 2.7.1 release; I consider it a bug in current behavior.

weierophinney added a commit that referenced this pull request Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
@fabiang fabiang deleted the creation-options-to-factories branch April 8, 2016 08:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants