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

Commit

Permalink
Merge branch 'fix/form-get-input-filter' of https://github.com/cgmart…
Browse files Browse the repository at this point in the history
…in/zf2 into hotfix/2624
  • Loading branch information
weierophinney committed Oct 2, 2012
2 parents 0d57603 + 4fd2d42 commit 62b12b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 16 additions & 4 deletions library/Zend/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class Form extends Fieldset implements FormInterface
*/
protected $useInputFilterDefaults = true;

/**
* Has the input filter defaults been added already ?
*
* @var bool
*/
protected $hasAddedInputFilterDefaults = false;

/**
* Whether or not validation has occurred
*
Expand Down Expand Up @@ -552,8 +559,9 @@ protected function prepareValidationGroup(FieldsetInterface $formOrFieldset, arr
*/
public function setInputFilter(InputFilterInterface $inputFilter)
{
$this->hasValidated = false;
$this->filter = $inputFilter;
$this->hasValidated = false;
$this->hasAddedInputFilterDefaults = false;
$this->filter = $inputFilter;
return $this;
}

Expand All @@ -577,12 +585,16 @@ public function getInputFilter()
}
}

if (null === $this->filter) {
if (!isset($this->filter)) {
$this->filter = new InputFilter();
}

if ($this->filter instanceof InputFilterInterface && $this->useInputFilterDefaults()) {
if (!$this->hasAddedInputFilterDefaults
&& $this->filter instanceof InputFilterInterface
&& $this->useInputFilterDefaults()
) {
$this->attachInputFilterDefaults($this->filter, $this);
$this->hasAddedInputFilterDefaults = true;
}

return $this->filter;
Expand Down
10 changes: 10 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ public function testCallingPrepareEnsuresInputFilterRetrievesDefaults()
$this->assertEquals(2, count($validators));
$this->assertTrue($input->isRequired());
$this->assertEquals('foo', $input->getName());

// Issue #2586 Ensure default filters aren't added twice
$filter = $this->form->getInputFilter();

$this->assertTrue($filter->has('foo'));
$input = $filter->get('foo');
$filters = $input->getFilterChain();
$this->assertEquals(1, count($filters));
$validators = $input->getValidatorChain();
$this->assertEquals(2, count($validators));
}

public function testCanProperlyPrepareNestedFieldsets()
Expand Down

0 comments on commit 62b12b5

Please sign in to comment.