This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -261,16 +261,18 @@ public function allowValueBinding()
261
261
* Bind values to the object
262
262
*
263
263
* @param array $values
264
+ * @param array $validationGroup
265
+ *
264
266
* @return array|mixed|void
265
267
*/
266
- public function bindValues (array $ values = [])
268
+ public function bindValues (array $ values = [], array $ validationGroup = null )
267
269
{
268
270
$ collection = [];
269
271
foreach ($ values as $ name => $ value ) {
270
272
$ element = $ this ->get ($ name );
271
273
272
274
if ($ element instanceof FieldsetInterface) {
273
- $ collection [] = $ element ->bindValues ($ value );
275
+ $ collection [] = $ element ->bindValues ($ value, $ validationGroup );
274
276
} else {
275
277
$ collection [] = $ value ;
276
278
}
Original file line number Diff line number Diff line change @@ -557,9 +557,11 @@ public function allowValueBinding()
557
557
* Bind values to the bound object
558
558
*
559
559
* @param array $values
560
+ * @param array $validationGroup
561
+ *
560
562
* @return mixed|void
561
563
*/
562
- public function bindValues (array $ values = [])
564
+ public function bindValues (array $ values = [], array $ validationGroup = null )
563
565
{
564
566
$ objectData = $ this ->extract ();
565
567
$ hydrator = $ this ->getHydrator ();
@@ -568,6 +570,10 @@ public function bindValues(array $values = [])
568
570
foreach ($ this ->iterator as $ element ) {
569
571
$ name = $ element ->getName ();
570
572
573
+ if ($ validationGroup && (array_key_exists ($ name , $ validationGroup ) || !in_array ($ name , $ validationGroup ))) {
574
+ continue ;
575
+ }
576
+
571
577
if (!array_key_exists ($ name , $ values )) {
572
578
if (!($ element instanceof Collection)) {
573
579
continue ;
@@ -579,7 +585,7 @@ public function bindValues(array $values = [])
579
585
$ value = $ values [$ name ];
580
586
581
587
if ($ element instanceof FieldsetInterface && $ element ->allowValueBinding ()) {
582
- $ value = $ element ->bindValues ($ value );
588
+ $ value = $ element ->bindValues ($ value, empty ( $ validationGroup [ $ name ]) ? null : $ validationGroup [ $ name ] );
583
589
}
584
590
585
591
// skip post values for disabled elements, get old value from object
Original file line number Diff line number Diff line change @@ -357,13 +357,14 @@ public function bindValues(array $values = [])
357
357
}
358
358
359
359
$ data = $ this ->prepareBindData ($ data , $ this ->data );
360
+ $ validationGroup = $ this ->getValidationGroup ();
360
361
361
362
// If there is a base fieldset, only hydrate beginning from the base fieldset
362
363
if ($ this ->baseFieldset !== null ) {
363
364
$ data = $ data [$ this ->baseFieldset ->getName ()];
364
- $ this ->object = $ this ->baseFieldset ->bindValues ($ data );
365
+ $ this ->object = $ this ->baseFieldset ->bindValues ($ data, $ validationGroup [ $ this -> baseFieldset -> getName ()] );
365
366
} else {
366
- $ this ->object = parent ::bindValues ($ data );
367
+ $ this ->object = parent ::bindValues ($ data, $ validationGroup );
367
368
}
368
369
}
369
370
Original file line number Diff line number Diff line change @@ -587,7 +587,7 @@ public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesT
587
587
$ this ->form ->setHydrator (new Hydrator \ObjectProperty ());
588
588
$ this ->form ->bind ($ model );
589
589
$ this ->form ->setData ($ dataWithoutCollection );
590
- $ this ->form ->setValidationGroup (array ( 'foo ' ) );
590
+ $ this ->form ->setValidationGroup ([ 'foo ' ] );
591
591
$ this ->form ->isValid ();
592
592
593
593
$ this ->assertObjectHasAttribute ('foo ' , $ model );
You can’t perform that action at this time.
0 commit comments