trrrrrrm
trrrrrrm

Reputation: 11812

Symfony2: Multiple Prototypes for an array field

I have an Entity Article which contains:

/**
 * @ORM\Column(type="array") 
 */
private $data;

My data field can be in different shapes, either (x1 & x2) or (y1, y2 & y3) .. etc.

I created a FormType for each one of them but i'm confused on how i present those prototypes to the ArticleType form and the user can be free to choose to insert either X or Y or multiple of those, I know i need a Collection for that with allow_add option but i need a way to insert multiple types in that collection.

My plan is to have X number of buttons, each button has a prototype, once the user click on that button, the prototype will be inserted to the form[data] field.

Any thoughts ?

Upvotes: 0

Views: 253

Answers (1)

Vera
Vera

Reputation: 742

To do so you should create a new form type similar to collection, but allowing several prototypes. see example implementation:
https://github.com/infinite-networks/InfiniteFormBundle/blob/master/Form/Type/PolyCollectionType.php
https://gist.github.com/merk/3058342

Upvotes: 5

Related Questions