How to add an entity with select 2 choices ?

Please tell me whether it is possible to do so: when typing in the string that does not correspond to any entity, the entity with the "name" was created and recorded in the database.
September 26th 19 at 06:32
2 answers
September 26th 19 at 06:34
what's stopping you, get this line in the controller to create this entity?

For example, received $city = $form->get('city')->getData(); to check whether such a city, and create it if not present? DataTransformer need to convert one format to another, as a recording entity not to use.
I do not agree. Take the classic example of creating a field for tags in the form is a string with a list of words/expressions, separated by commas. Our database each tag is an entry in the tag table + table entry linking the tag with the desired essence. Sequence of operations:
1) Create new forms of the type field of tags that inherit from text or hidden (for example, if you want to use the library for autocomplete type select2)
2) Create a transformer from strings to tags and back. The first example that I found Google:
3) In the form of a type tag in buildForm add our transformer. An example from the same project from Google: - omari_Hand25 commented on September 26th 19 at 06:37
I meant to write in the data transformer in the base is impossible, in this bundle record is not in the base of the transformer - joelle commented on September 26th 19 at 06:40
September 26th 19 at 06:36
With shapes in Symphony, you can do anything. The easiest option in my opinion - DataTransformer to write your own.

Find more questions by tags PHPSymfony