Теперь у меня есть ограничение выражения в моей сущности, вот так:
Код: Выделить всё
/**
* @ORM\Column(type="string", length=255)
* @Assert\Choice(choices=TypeConge::TYPE_SOLDE, message="Veuillez choisir une valeur valide.")
* @Assert\Expression(
* "not (this.getId() != null and this.getTypeSolde() != this.getConfirmTypeSolde())",
* message="Vous ne pouvez pas modifier le type de solde d'un type de congé que vous avez déjà créé ! ({{ value }})"
* )
*/
private ?string $typeSolde = null;
В моем FormType я:
Код: Выделить всё
->add('typeSolde', ChoiceType::class, [
//...
'constraints' => [
new Expression([
'expression' => 'not (this.getId() != null and this.getTypeSolde() != this.getConfirmTypeSolde())',
'message' => "Vous ne pouvez pas modifier le type de solde d'un type de congé que vous avez déjà créé ! ({{ value }})"
])
]
])
Код: Выделить всё
Unable to call method "getId" of object "Symfony\Component\Form\Form".
Подробнее здесь: https://stackoverflow.com/questions/674 ... -in-a-form
Мобильная версия