File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,18 +29,21 @@ class ConstraintFactory
2929 /**
3030 * @param Constraint $validationConstraint
3131 * @param FormInterface $form
32- * @return ConstraintInterface
32+ * @return ConstraintInterface|null
3333 * @throws \Exception
3434 * @throws \InvalidArgumentException
3535 * @throws \RuntimeException
3636 */
3737 public static function createFromValidationConstraint (
3838 Constraint $ validationConstraint ,
3939 FormInterface $ form
40- ): ConstraintInterface {
40+ ): ? ConstraintInterface {
4141 // TODO Change this to use the ViewInterface instead of the FormInterface as that makes a lot more sense!
4242
43- if ($ validationConstraint instanceof \Symfony \Component \Validator \Constraints \NotNull) {
43+ if ($ validationConstraint instanceof \Symfony \Component \Validator \Constraints \Valid) {
44+ // This case is not an error. There just isn't a 'like-for-like' replacement
45+ return null ;
46+ } elseif ($ validationConstraint instanceof \Symfony \Component \Validator \Constraints \NotNull) {
4447 return new Required ($ validationConstraint ->message );
4548 } elseif ($ validationConstraint instanceof \Symfony \Component \Validator \Constraints \NotBlank) {
4649 return new Required ($ validationConstraint ->message );
Original file line number Diff line number Diff line change @@ -100,7 +100,10 @@ private function createParsleyConstraintsFromValidationConstraints(
100100 $ out = [];
101101 foreach ($ validationConstraints as $ validationConstraint ) {
102102 try {
103- $ out [] = ConstraintFactory::createFromValidationConstraint ($ validationConstraint , $ form );
103+ $ parsleyConstraint = ConstraintFactory::createFromValidationConstraint ($ validationConstraint , $ form );
104+ if ($ parsleyConstraint !== null ) {
105+ $ out [] = $ parsleyConstraint ;
106+ }
104107 } catch (\RuntimeException $ exception ) {
105108 // Don't care for now!
106109 // TODO How loud this should be should be configurable
Original file line number Diff line number Diff line change 2323use Symfony \Component \Validator \Constraints \NotBlank ;
2424use Symfony \Component \Validator \Constraints \NotNull ;
2525use Symfony \Component \Validator \Constraints \Regex ;
26+ use Symfony \Component \Validator \Constraints \Valid ;
2627use Symfony \Component \Validator \ConstraintViolationList ;
2728use Symfony \Component \Validator \Mapping \ClassMetadata ;
2829use Symfony \Component \Validator \Validator \ValidatorInterface ;
@@ -66,6 +67,12 @@ public function getFactoryTestData()
6667 $ form = $ factory ->create (TestType::class, null , []);
6768
6869 return [
70+ [
71+ new Valid (),
72+ $ form ->get ('id ' ),
73+ null ,
74+ 'Valid to Null ' ,
75+ ],
6976 [
7077 new NotNull (['message ' => 'Give me something ' ]),
7178 $ form ->get ('id ' ),
You can’t perform that action at this time.
0 commit comments