Mam pewien problem, posiadam walidację encji która zawiera kolekcję encji pod konkretnym property, uzupełniane jest wszystko przez formularz z opcją dodawania nowego wpisu.
$builder //... ->add('someProperty', CollectionType::class, [ 'entry_type' => SomeNestedEntityType::class, 'allow_add' => true ]);
Kod
SomeBundleBundle\Entity\SomeEntity:
properties:
someNestedEntities:
- Valid: ~
- Count:
min: 1
groups: [DEFAULT]
properties:
someNestedEntities:
- Valid: ~
- Count:
min: 1
groups: [DEFAULT]
Kod
SomeBundle\Entity\SomeNestedEntity:
properties:
value:
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
- Type:
type: float
groups: [DEFAULT, AUTO]
- Type:
type: string
groups: [PERIODIC]
strategy:
- Choice:
choices: [single, shared, everyone]
groups: [DEFAULT, AUTO]
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
placement:
- GreaterThan:
value: 0
groups: [DEFAULT]
- Type:
type: integer
groups: [DEFAULT]
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
properties:
value:
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
- Type:
type: float
groups: [DEFAULT, AUTO]
- Type:
type: string
groups: [PERIODIC]
strategy:
- Choice:
choices: [single, shared, everyone]
groups: [DEFAULT, AUTO]
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
placement:
- GreaterThan:
value: 0
groups: [DEFAULT]
- Type:
type: integer
groups: [DEFAULT]
- NotBlank:
groups: [DEFAULT]
- NotNull:
groups: [DEFAULT]
Całość to form, zastosowanie czysto RESTowe.
Problem:
Pole placement w SomeNestedEntity powinno być walidowane w formie x, x+1, x+2, x+3...x+n, tj. nie może wystąpić przerwa w nadawaniu kolejnych numerów, ale nie ma ograniczenia co do "początku" za wyjątkiem tego, że muszą być od siebie różne, musi być int oraz muszą być zajęte wszystkie...indexy? bo tak to chyba można nazwać. Nie ma znaczenia kolejność ich ułożenia w tablicy.
Pytanie:
Jak to dobrze ograć, żeby wszystkie warunki były spełnione? Nie ukrywam, że Constraint na klasę wydaje mi się najodpowiedniejszy, aczkolwiek jak ogarnąć weryfikację zajętości indexów w kolekcji z poziomu elementu który do niej dostępu nie ma?
Inny pomysł?