There are even simpler solutions than creating a custom validator. The simplest of these is probably the expression constraint:
class MyEntity { private $fieldA; private $fieldB; private $fieldC; }
You can also add a validation method to your class and annotate it with a callback restriction:
public function validateFields(ExecutionContextInterface $context) { if ('' === $this->fieldA && '' === $this->fieldB && '' === $this->fieldC) { $context->addViolation('At least one of the fields must be filled'); } }
The method will be executed during class verification.
Bernhard schussek
source share