I think that you are already on the right track, as I saw your other question about the type of form. I will just reassure you of your choice.
Type type is probably the best way. With the type of form, you can display a single text field in your form. You can also convert the data to a string for display to the user and ArrayCollection to set it in your model. For this, you use the DataTransformer in the same way as in your other question.
With this technology, you do not need an additional tagsInput field in your model; you can only have one field named tags , which will be an ArrayCollection . Having one field is possible because the type of the form will convert this data from a string to an ArrayCollection .
For verification, I think you could use the Choice validator. This validator directive is apparently able to verify that an array has no fewer elements and no more than another number. Here you can check the documentation here . You would use it as follows:
// src/Acme/BlogBundle/Entity/Author.php use Symfony\Component\Validator\Constraints as Assert; class Post { /** * @Assert\Choice(min = 1, max = 32) */ protected $tags; }
If this does not work or is not intended, then you can create a custom validator. This validator will be placed in your model for the tags field. This validator will verify that the array has a maximum number of elements not exceeding a fixed number (32 in your case).
Hope this helps.
Respectfully,
Matt
source share