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

Commit

Permalink
Merge branch 'hotfix/24' into develop
Browse files Browse the repository at this point in the history
Forward port #24
  • Loading branch information
weierophinney committed Apr 7, 2016
2 parents 8b53e9a + 8f16d3a commit c84c109
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

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

## 2.7.0 - 2016-02-22

Expand Down
2 changes: 2 additions & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ public function getInputFilter()
$name = $this->baseFieldset->getName();
if (!$this->filter instanceof InputFilterInterface || !$this->filter->has($name)) {
$filter = new InputFilter();
$filter->setFactory($this->getFormFactory()->getInputFilterFactory());
$filter->add($this->object->getInputFilter(), $name);
$this->filter = $filter;
}
Expand All @@ -687,6 +688,7 @@ public function getInputFilter()

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

if (!$this->hasAddedInputFilterDefaults
Expand Down
23 changes: 23 additions & 0 deletions test/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2135,4 +2135,27 @@ public function testSetValidationGroupOnFormWithNestedCollectionsPopulatesOnlyFi

$this->assertEquals($data, $this->form->getData());
}

/**
* Test for https://github.com/zendframework/zend-form/pull/24#issue-119023527
*/
public function testGetInputFilterInjectsFormInputFilterFactoryInstanceObjectIsNull()
{
$inputFilterFactory = $this->form->getFormFactory()->getInputFilterFactory();
$inputFilter = $this->form->getInputFilter();
$this->assertSame($inputFilterFactory, $inputFilter->getFactory());
}

/**
* Test for https://github.com/zendframework/zend-form/pull/24#issuecomment-159905491
*/
public function testGetInputFilterInjectsFormInputFilterFactoryInstanceWhenObjectIsInputFilterAware()
{
$this->form->setBaseFieldset(new Fieldset());
$this->form->setHydrator(new Hydrator\ClassMethods());
$this->form->bind(new TestAsset\Entity\Cat());
$inputFilterFactory = $this->form->getFormFactory()->getInputFilterFactory();
$inputFilter = $this->form->getInputFilter();
$this->assertSame($inputFilterFactory, $inputFilter->getFactory());
}
}
70 changes: 70 additions & 0 deletions test/TestAsset/Entity/Cat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Form\TestAsset\Entity;

use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterInterface;
use Zend\InputFilter\InputFilterAwareInterface;

class Cat implements InputFilterAwareInterface
{
/**
* @var string
*/
protected $name = null;

/**
* @var InputFilterInterface
*/
protected $inputFilter = null;

/**
* @param string $name
* @return Cat
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Set input filter
*
* @param InputFilterInterface $inputFilter
* @return Cat
*/
public function setInputFilter(InputFilterInterface $inputFilter)
{
$this->inputFilter = $inputFilter;
return $this;
}

/**
* Retrieve input filter
*
* @return InputFilterInterface
*/
public function getInputFilter()
{
if (null === $this->inputFilter) {
$this->inputFilter = new InputFilter();
}
return $this->inputFilter;
}
}

0 comments on commit c84c109

Please sign in to comment.