Created
May 10, 2011 11:01
-
-
Save johnwards/964272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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