Skip to content

Instantly share code, notes, and snippets.

@johnwards
Created May 10, 2011 11:01
Show Gist options
  • Save johnwards/964272 to your computer and use it in GitHub Desktop.
Save johnwards/964272 to your computer and use it in GitHub Desktop.
<?php
$symfonyFormBuilder = $this->get('form.factory')
->createBuilder('form');
//An array of elements
$elements = array();
$symfonyFormBuilder->setAttribute('validation_constraint', new Callback(array("methods"=>array(
'validate' => function ($data, $context) use ($elements) {
// logic to add violations depending on the elements
foreach($elements as $hash => $element) {
$constraints = $element->getConstraints();
foreach($constraints as $constraint) {
$context->getGraphWalker()->walkConstraint($constraint, (isset($data[$hash]))?$data[$hash]:'', array(), 'children['.$hash.']');
}
}
}
))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment