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

Commit

Permalink
Ensure input-provider elements of collections merge inputs correctly
Browse files Browse the repository at this point in the history
As reported in #78, if you compose an input filter provider fieldset as
a target element of a collection in order to allow providing a default
fieldset for the collection, input provider elements composed by the
input filter provider fieldset were not being merged correctly into the
input filter.

This patch checks to see if the fieldset's input filter represents a
collection, and, if so, will check its own composed input filter for the
element and merge it if found.
  • Loading branch information
weierophinney committed Apr 26, 2017
1 parent 5239951 commit 2a0dfe5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,19 @@ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, Fie
$inputFilter->replace($input, $name);
continue;
}

// If we are dealing with a collection input filter, check
// the input filter it composes for an element of the same
// name as was done above.
if ($inputFilter instanceof CollectionInputFilter
&& $inputFilter->getInputFilter()->has($name)
&& $inputFilter->getInputFilter() instanceof ReplaceableInputInterface
) {
$collectionInputFilter = $inputFilter->getInputFilter();
$input->merge($collectionInputFilter->get($name));
$collectionInputFilter->replace($input, $name);
continue;
}
}

// Add element input filter to CollectionInputFilter
Expand Down
6 changes: 4 additions & 2 deletions test/Integration/FormCreatesCollectionInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class FormCreatesCollectionInputFilterTest extends TestCase
public static function assertValidatorFound($class, array $validators, $message = null)
{
$message = $message ?: sprintf('Failed to find validator of type %s in validator list', $class);
foreach ($validators as $validator) {
foreach ($validators as $instance) {
$validator = $instance['instance'];
if ($validator instanceof $class) {
return true;
}
}
var_export($validators);
self::fail($message);
}

Expand Down Expand Up @@ -63,7 +65,7 @@ public function testCollectionInputFilterContainsExpectedValidators()
$this->assertCount(3, $validators);
$this->assertValidatorFound(Validator\StringLength::class, $validators);
$this->assertValidatorFound(Validator\Date::class, $validators);
$this->assertValidatorFound(Validator\Step::class, $validators);
$this->assertValidatorFound(Validator\DateStep::class, $validators);

return $form;
}
Expand Down

0 comments on commit 2a0dfe5

Please sign in to comment.