Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. use SymfonyComponentValidatorConstraints as Assert;
  2. use SymfonyComponentValidatorExecutionContextInterface;
  3.  
  4. //...
  5.  
  6. public function buildForm(FormBuilderInterface $builder, array $options) {
  7. parent::buildForm($builder, $options);
  8. $builder->add('enabled', 'checkbox', array(
  9. 'required' => false,
  10. 'constraints' => array(
  11. new AssertCallback(array(
  12. 'callback' => array(
  13. $this,
  14. 'validateisReady'),
  15. 'groups' => $this->validationGroups))
  16. ),
  17. ))
  18. ;
  19. }
  20.  
  21. public static function validateisReady($object, ExecutionContextInterface $context) {
  22.  
  23. //..
  24. if($object->getItems()->count() < 1){
  25. $context->addViolationAt('enabled', 'items.missing');
  26. }
  27. //..
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement