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

[Form] [Hotfix] Get Elements for Collection #4231

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion library/Zend/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,13 @@ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, Fie
}
}

foreach ($fieldset->getElements() as $element) {
if ($fieldset instanceof Collection && $fieldset->getTargetElement() instanceof FieldsetInterface) {
$elements = $fieldset->getTargetElement()->getElements();
} else {
$elements = $fieldset->getElements();
}

foreach ($elements as $element) {
$name = $element->getName();

if ($this->preferFormInputFilter && $inputFilter->has($name)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ public function testDonNotApplyEmptyInputFiltersToSubFieldsetOfCollectionElement
$this->form->setInputFilter($inputFilter);

$this->assertInstanceOf('Zend\InputFilter\CollectionInputFilter', $this->form->getInputFilter()->get('items'));
$this->assertCount(0, $this->form->getInputFilter()->get('items')->getInputs());
$this->assertCount(1, $this->form->getInputFilter()->get('items')->getInputs());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this might be a regression, as you had to change a test assertion.

@bakura10 -- can you review?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my own test assertion for the new CollectionInputFilter (not yet in master).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidwindell I forgot that this was on develop. :)


public function testFormValidationCanHandleNonConsecutiveKeysOfCollectionInData()
Expand Down