Let's start with a background.
I need user profile that will have basic info like name, email, phone etc. And for that I have an entity User.
I also need to store answers from a questionnaire. I was thinking to store them in database as a json in a text field. Those questions can change in the future, there are currently ~30 questions so I don't want to store it as an entity. So currently in my User entity I have this:
/**
* @var array
*
* @ORM\Column(name="questionnaire", type="json_array", nullable=true)
*/
private $questionnaire;
I understand that Symfony will take care of json_encode/json_decode thing. So this is great.
But now, I have a bit of problem with creating a form with the symfony builder.
First I thought I could try something like this:
$builder->add('questionnaire[source]');
Which doesn't work. For symfony masters it's obvious I know ;o)
So currently my choices I see are: CollectionType or Data Transformers.
From what I see, CollectionType will not work, as it's only work with numeric arrays where we have field with some JS "Add another row" or something. http://symfony.com/doc/current/reference/forms/types/collection.html#adding-and-removing-items But if I'm wrong about this and I should go with CollectionType and there is some magic way please tell me. I can't find much about this.
So I was thinking Data Transformers or simply creating an array on submit without this Transformer thing. Create all fields that are in Questionnaire with the "mapped=>false" and then set those submitted values as an associative array to $questionnaire. This "feels" ok, but I'm not sure how to later handle this in "Edit" form (from docs I think with this http://symfony.com/doc/current/reference/forms/types/form.html#data).
Questionnaire itself will have many ChoiceType fields, a CollectionType with "Add more row" and so on and it will have lots of questions. So it will be a bit complex. I would like to avoid creating entity for that with each question as a property (not sure if it's a right choice, but considering everything I believe it's the best one).
This is my first date with symfony so any help/tips appreciate.