Skip to content

Instantly share code, notes, and snippets.

@oziks
Created September 17, 2013 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oziks/6591116 to your computer and use it in GitHub Desktop.
Save oziks/6591116 to your computer and use it in GitHub Desktop.
Validate Symfony Form Type with Entity method
<?php
....
/**
* Validate Method
*
* @param ExecutionContext $context Execution context
*
* @return void
*/
public function validateMethod(ExecutionContext $context)
{
$context->addViolationAt('fields', 'Error Message.');
}
....
<?php
....
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
....
'constraints' => array(
new Assert\Callback(array('methods' => array('validateMethod'))),
),
));
}
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment