EventFieldsValidator.php 891 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace WorkflowBundle\Validator;
  3. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  4. use WorkflowBundle\Utils\DoctrineEvents;
  5. use WorkflowBundle\Utils\WorkFlowEvents;
  6. use WorkflowBundle\Entity\Action;
  7. class EventFieldsValidator
  8. {
  9. /**
  10. * @param string $value
  11. * @param ExecutionContextInterface $context
  12. * @param array $payload
  13. */
  14. public static function validate($value, ExecutionContextInterface $context, $payload)
  15. {
  16. /* @var $entity Action */
  17. $entity = $context->getObject();
  18. $class = isset($payload['doctrine']) ? DoctrineEvents::class : WorkFlowEvents::class;
  19. if (!empty(array_intersect($entity->getEvent(), $class::getChoices())) && is_null($value)) {
  20. $context->buildViolation('error.event_field_required')
  21. ->addViolation()
  22. ;
  23. }
  24. }
  25. }