Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 8991ddb

Browse files
committed
fixed #102 do not ignore validation group for collections
1 parent f2218e4 commit 8991ddb

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/Element/Collection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,18 @@ public function allowValueBinding()
261261
* Bind values to the object
262262
*
263263
* @param array $values
264+
* @param array $validationGroup
265+
*
264266
* @return array|mixed|void
265267
*/
266-
public function bindValues(array $values = [])
268+
public function bindValues(array $values = [], array $validationGroup = null)
267269
{
268270
$collection = [];
269271
foreach ($values as $name => $value) {
270272
$element = $this->get($name);
271273

272274
if ($element instanceof FieldsetInterface) {
273-
$collection[] = $element->bindValues($value);
275+
$collection[] = $element->bindValues($value, $validationGroup);
274276
} else {
275277
$collection[] = $value;
276278
}

src/Fieldset.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,11 @@ public function allowValueBinding()
557557
* Bind values to the bound object
558558
*
559559
* @param array $values
560+
* @param array $validationGroup
561+
*
560562
* @return mixed|void
561563
*/
562-
public function bindValues(array $values = [])
564+
public function bindValues(array $values = [], array $validationGroup = null)
563565
{
564566
$objectData = $this->extract();
565567
$hydrator = $this->getHydrator();
@@ -568,6 +570,10 @@ public function bindValues(array $values = [])
568570
foreach ($this->iterator as $element) {
569571
$name = $element->getName();
570572

573+
if ($validationGroup && (array_key_exists($name, $validationGroup) || !in_array($name, $validationGroup))) {
574+
continue;
575+
}
576+
571577
if (!array_key_exists($name, $values)) {
572578
if (!($element instanceof Collection)) {
573579
continue;
@@ -579,7 +585,7 @@ public function bindValues(array $values = [])
579585
$value = $values[$name];
580586

581587
if ($element instanceof FieldsetInterface && $element->allowValueBinding()) {
582-
$value = $element->bindValues($value);
588+
$value = $element->bindValues($value, empty($validationGroup[$name]) ? null : $validationGroup[$name]);
583589
}
584590

585591
// skip post values for disabled elements, get old value from object

src/Form.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,14 @@ public function bindValues(array $values = [])
357357
}
358358

359359
$data = $this->prepareBindData($data, $this->data);
360+
$validationGroup = $this->getValidationGroup();
360361

361362
// If there is a base fieldset, only hydrate beginning from the base fieldset
362363
if ($this->baseFieldset !== null) {
363364
$data = $data[$this->baseFieldset->getName()];
364-
$this->object = $this->baseFieldset->bindValues($data);
365+
$this->object = $this->baseFieldset->bindValues($data, $validationGroup[$this->baseFieldset->getName()]);
365366
} else {
366-
$this->object = parent::bindValues($data);
367+
$this->object = parent::bindValues($data, $validationGroup);
367368
}
368369
}
369370

test/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public function testSettingValidationGroupWithoutCollectionBindsOnlyThoseValuesT
587587
$this->form->setHydrator(new Hydrator\ObjectProperty());
588588
$this->form->bind($model);
589589
$this->form->setData($dataWithoutCollection);
590-
$this->form->setValidationGroup(array('foo'));
590+
$this->form->setValidationGroup(['foo']);
591591
$this->form->isValid();
592592

593593
$this->assertObjectHasAttribute('foo', $model);

0 commit comments

Comments
 (0)