Permalink
Browse files

Bugfix 2586 Form: default input filters added multiple times

  • Loading branch information...
1 parent c42f0bd commit 4fd2d42e58245f03d1909306a8ef8858974611b1 @cgmartin committed Sep 30, 2012
Showing with 26 additions and 4 deletions.
  1. +16 −4 library/Zend/Form/Form.php
  2. +10 −0 tests/ZendTest/Form/FormTest.php
@@ -79,6 +79,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
*
* @var bool
@@ -558,8 +565,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;
}
@@ -583,12 +591,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;
@@ -778,6 +778,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()

0 comments on commit 4fd2d42

Please sign in to comment.