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

Inject input filter factory when creating new input filter #24

Merged
merged 7 commits into from
Apr 7, 2016
Merged

Conversation

ffraenz
Copy link
Contributor

@ffraenz ffraenz commented Nov 26, 2015

Custom validators and filters are not available in forms pulled from the FormElementManager. I already discussed this issue here.

When the object bound to the form does not implement InputFilterAwareInterface, the form creates its InputFilter instance itself when getInputFilter gets called:

$this->filter = new InputFilter();

In this case, the Zend\InputFilter\Factory dependency of this newly created input filter instance does not get satisfied which results in creating a different factory instance with separate ServiceManagers lazily.

The form has a pointer to a Zend\InputFilter\Factory instance with properly injected ServiceManagers. Adding following line right after the statement shown above makes custom filters and validators available inside the form as expected:

$this->filter->setFactory($this->getFormFactory()->getInputFilterFactory());

Both getFormFactory and getInputFilterFactory create instances lazily if they have not been injected. This statement should never fail.

@Maks3w
Copy link
Member

Maks3w commented Nov 26, 2015

Need tests

@ffraenz ffraenz changed the title Inject input filter factory Inject input filter factory when creating new input filter Nov 26, 2015
@ffraenz
Copy link
Contributor Author

ffraenz commented Nov 26, 2015

I test if getInputFilter creates a new input filter having the same factory instance injected as set in the form's factory. This is true when the factory instances are lazily created and when they are injected by service managers.

@Maks3w
Copy link
Member

Maks3w commented Nov 26, 2015

Factory should be set too after the inputfilter created on line 681

@ffraenz
Copy link
Contributor Author

ffraenz commented Nov 26, 2015

That should do.

@ffraenz
Copy link
Contributor Author

ffraenz commented Dec 15, 2015

Do you consider merging? Is there anything else you need?

@weierophinney weierophinney added this to the 2.7.1 milestone Apr 7, 2016
@weierophinney weierophinney self-assigned this Apr 7, 2016
@weierophinney weierophinney merged commit 33726ff into zendframework:master Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
Inject input filter factory when creating new input filter
weierophinney added a commit that referenced this pull request Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
weierophinney added a commit that referenced this pull request Apr 7, 2016
@weierophinney
Copy link
Member

Sorry for the delay reviewing and merging, @ffraenz - merged now, and will be released in a 2.7.1 version soon.

@ffraenz ffraenz deleted the patch-1 branch April 7, 2016 22:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants