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

Commit c84c109

Browse files
committed
Merge branch 'hotfix/24' into develop
Forward port #24
2 parents 8b53e9a + 8f16d3a commit c84c109

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39-
- Nothing.
39+
- [#24](https://github.com/zendframework/zend-form/pull/24) ensures that when
40+
`Zend\Form\Form::getInputFilter()` when lazy-creates an `InputFilter`
41+
instance, it is populated with the `InputFilterFactory` present in its own
42+
`FormFactory`. This ensures that any custom inputs, input filters, validators,
43+
or filters are available to the new instance.
4044

4145
## 2.7.0 - 2016-02-22
4246

src/Form.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ public function getInputFilter()
679679
$name = $this->baseFieldset->getName();
680680
if (!$this->filter instanceof InputFilterInterface || !$this->filter->has($name)) {
681681
$filter = new InputFilter();
682+
$filter->setFactory($this->getFormFactory()->getInputFilterFactory());
682683
$filter->add($this->object->getInputFilter(), $name);
683684
$this->filter = $filter;
684685
}
@@ -687,6 +688,7 @@ public function getInputFilter()
687688

688689
if (!isset($this->filter)) {
689690
$this->filter = new InputFilter();
691+
$this->filter->setFactory($this->getFormFactory()->getInputFilterFactory());
690692
}
691693

692694
if (!$this->hasAddedInputFilterDefaults

test/FormTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,4 +2135,27 @@ public function testSetValidationGroupOnFormWithNestedCollectionsPopulatesOnlyFi
21352135

21362136
$this->assertEquals($data, $this->form->getData());
21372137
}
2138+
2139+
/**
2140+
* Test for https://github.com/zendframework/zend-form/pull/24#issue-119023527
2141+
*/
2142+
public function testGetInputFilterInjectsFormInputFilterFactoryInstanceObjectIsNull()
2143+
{
2144+
$inputFilterFactory = $this->form->getFormFactory()->getInputFilterFactory();
2145+
$inputFilter = $this->form->getInputFilter();
2146+
$this->assertSame($inputFilterFactory, $inputFilter->getFactory());
2147+
}
2148+
2149+
/**
2150+
* Test for https://github.com/zendframework/zend-form/pull/24#issuecomment-159905491
2151+
*/
2152+
public function testGetInputFilterInjectsFormInputFilterFactoryInstanceWhenObjectIsInputFilterAware()
2153+
{
2154+
$this->form->setBaseFieldset(new Fieldset());
2155+
$this->form->setHydrator(new Hydrator\ClassMethods());
2156+
$this->form->bind(new TestAsset\Entity\Cat());
2157+
$inputFilterFactory = $this->form->getFormFactory()->getInputFilterFactory();
2158+
$inputFilter = $this->form->getInputFilter();
2159+
$this->assertSame($inputFilterFactory, $inputFilter->getFactory());
2160+
}
21382161
}

test/TestAsset/Entity/Cat.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Form\TestAsset\Entity;
11+
12+
use Zend\InputFilter\InputFilter;
13+
use Zend\InputFilter\InputFilterInterface;
14+
use Zend\InputFilter\InputFilterAwareInterface;
15+
16+
class Cat implements InputFilterAwareInterface
17+
{
18+
/**
19+
* @var string
20+
*/
21+
protected $name = null;
22+
23+
/**
24+
* @var InputFilterInterface
25+
*/
26+
protected $inputFilter = null;
27+
28+
/**
29+
* @param string $name
30+
* @return Cat
31+
*/
32+
public function setName($name)
33+
{
34+
$this->name = $name;
35+
return $this;
36+
}
37+
38+
/**
39+
* @return string
40+
*/
41+
public function getName()
42+
{
43+
return $this->name;
44+
}
45+
46+
/**
47+
* Set input filter
48+
*
49+
* @param InputFilterInterface $inputFilter
50+
* @return Cat
51+
*/
52+
public function setInputFilter(InputFilterInterface $inputFilter)
53+
{
54+
$this->inputFilter = $inputFilter;
55+
return $this;
56+
}
57+
58+
/**
59+
* Retrieve input filter
60+
*
61+
* @return InputFilterInterface
62+
*/
63+
public function getInputFilter()
64+
{
65+
if (null === $this->inputFilter) {
66+
$this->inputFilter = new InputFilter();
67+
}
68+
return $this->inputFilter;
69+
}
70+
}

0 commit comments

Comments
 (0)