I'm using a form(parent form) with a collection field type(child forms). Each type in the collection is a form that contains some choice fields, I want to filter this field choices using query_builder parameter for join with other entities ect. I know how to pass parameters to parent form from controller, but how to pass parameters to each item in the collection (child forms)?
3 Answers
What you want is a data transformer. The data transformer takes data from your sub forms allows you to do queries to the database from inside it and pass 1 final result out the end. I had to do this the other day with country and postal code to find a valid postal code in a country.
Here's the link to the cookbook info that will show you how to use it.
http://symfony.com/doc/current/cookbook/form/data_transformers.html
Comments
Here is my answer: https://stackoverflow.com/a/17223519/1756517
In each form, pass the variable by the construct method ($form = new FormType($your_variable);)
Comments
A bit late response, but with Symfony3, you should use the entry_options parameter as mentioned here. It was exactly what I needed, in scenario similar to yours.
$optionsarray that's passed tobuildForm()?