I have an app where you can select partials which will be used for generating a full document. Partials are divided into categories. And there are 2 types of partials:
- "invisible" - will be included always when category has been selected
- "selectable" - will be included if both category and this partial has been selected
Example:
- Category: Automotive
- Invisible partial A.1: Introduction
- Selectable partial A.2: Comparison table
- Category: IT
- Invisible partial IT.1: Introduction
- Selectable partial IT.2: Comparison table
This should be rendered as:
[ ] Automotive
[ ] Comparison table
[ ] IT
[ ] Comparison table
Selected partials (both invisibile and selectable) are copied are into a separate doc_partial table as their content is could to be changed. For example if I select them like this:
[x] Automotive
[x] Comparison table
[x] IT
[ ] Comparison table
...that means following partials are copied into doc_partial:
- A.1 - because Automotive was selected
- A.2 - because Automotive AND A.2 was selected
- IT.1 - because IT was selected
User can also change document structure later, i.e if I deselect Automotive category then partials A.1 and A.2 are removed.
My question is - how to achieve this thing, where model is totally different compared to form, with Symfony Form Builder? In summary:
- categories exist only on form, invisible partials only in model
- checkbox value must contain whether it is category or partial
- the number of models and checkboxes are different
What I have right now:
- FormEvent preSubmit listener to convert Category checkboxes to Invisibile partials
- ViewTransformer.reverseTransform transforms (after preSubmit) checkbox values (partial IDs) to existing DocumentPartial record or creates new ones
- ViewTransformer.transform transforms existing DocumentPartials to category and partial checkbox values
- checkboxes are rendered separately, not by Form Builder :)
This whole thing has gotten too complex and Im starting to think I am doing it wrong :) What is the magic method here that "will do it as I need"?