File tree 4 files changed +34
-5
lines changed
src/Symfony/Component/Form 4 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -156,3 +156,4 @@ CHANGELOG
156
156
consumed by HTML5 browsers, if the widget is "single_text"
157
157
* deprecated the options "data_timezone" and "user_timezone" in DateType, DateTimeType and TimeType
158
158
and renamed them to "model_timezone" and "view_timezone"
159
+ * fixed: TransformationFailedExceptions thrown in the model transformer are now caught by the form
Original file line number Diff line number Diff line change @@ -171,7 +171,13 @@ public function guessTypeForConstraint(Constraint $constraint)
171
171
172
172
case 'Symfony\Component\Validator\Constraints\Url ' :
173
173
return new TypeGuess ('url ' , array (), Guess::HIGH_CONFIDENCE );
174
+
175
+ case 'Symfony\Component\Validator\Constraints\True ' :
176
+ case 'Symfony\Component\Validator\Constraints\False ' :
177
+ return new TypeGuess ('checkbox ' , array (), Guess::MEDIUM_CONFIDENCE );
174
178
}
179
+
180
+ return null ;
175
181
}
176
182
177
183
/**
@@ -186,8 +192,11 @@ public function guessRequiredForConstraint(Constraint $constraint)
186
192
switch (get_class ($ constraint )) {
187
193
case 'Symfony\Component\Validator\Constraints\NotNull ' :
188
194
case 'Symfony\Component\Validator\Constraints\NotBlank ' :
195
+ case 'Symfony\Component\Validator\Constraints\True ' :
189
196
return new ValueGuess (true , Guess::HIGH_CONFIDENCE );
190
197
}
198
+
199
+ return null ;
191
200
}
192
201
193
202
/**
@@ -215,6 +224,8 @@ public function guessMaxLengthForConstraint(Constraint $constraint)
215
224
case 'Symfony\Component\Validator\Constraints\Size ' :
216
225
return new ValueGuess (strlen ((string ) $ constraint ->max ), Guess::LOW_CONFIDENCE );
217
226
}
227
+
228
+ return null ;
218
229
}
219
230
220
231
/**
@@ -250,6 +261,8 @@ public function guessPatternForConstraint(Constraint $constraint)
250
261
}
251
262
break ;
252
263
}
264
+
265
+ return null ;
253
266
}
254
267
255
268
/**
Original file line number Diff line number Diff line change @@ -544,11 +544,7 @@ public function bind($submittedData)
544
544
try {
545
545
// Normalize data to unified representation
546
546
$ normData = $ this ->viewToNorm ($ viewData );
547
- $ synchronized = true ;
548
- } catch (TransformationFailedException $ e ) {
549
- }
550
547
551
- if ($ synchronized ) {
552
548
// Hook to change content of the data into the normalized
553
549
// representation
554
550
$ event = new FormEvent ($ this , $ normData );
@@ -560,6 +556,9 @@ public function bind($submittedData)
560
556
// Synchronize representations - must not change the content!
561
557
$ modelData = $ this ->normToModel ($ normData );
562
558
$ viewData = $ this ->normToView ($ normData );
559
+
560
+ $ synchronized = true ;
561
+ } catch (TransformationFailedException $ e ) {
563
562
}
564
563
565
564
$ this ->bound = true ;
Original file line number Diff line number Diff line change @@ -480,7 +480,7 @@ public function testSynchronizedAfterBinding()
480
480
$ this ->assertTrue ($ this ->form ->isSynchronized ());
481
481
}
482
482
483
- public function testNotSynchronizedIfTransformationFailed ()
483
+ public function testNotSynchronizedIfViewReverseTransformationFailed ()
484
484
{
485
485
$ transformer = $ this ->getDataTransformer ();
486
486
$ transformer ->expects ($ this ->once ())
@@ -496,6 +496,22 @@ public function testNotSynchronizedIfTransformationFailed()
496
496
$ this ->assertFalse ($ form ->isSynchronized ());
497
497
}
498
498
499
+ public function testNotSynchronizedIfModelReverseTransformationFailed ()
500
+ {
501
+ $ transformer = $ this ->getDataTransformer ();
502
+ $ transformer ->expects ($ this ->once ())
503
+ ->method ('reverseTransform ' )
504
+ ->will ($ this ->throwException (new TransformationFailedException ()));
505
+
506
+ $ form = $ this ->getBuilder ()
507
+ ->addModelTransformer ($ transformer )
508
+ ->getForm ();
509
+
510
+ $ form ->bind ('foobar ' );
511
+
512
+ $ this ->assertFalse ($ form ->isSynchronized ());
513
+ }
514
+
499
515
public function testEmptyDataCreatedBeforeTransforming ()
500
516
{
501
517
$ form = $ this ->getBuilder ()
You can’t perform that action at this time.
0 commit comments