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/216' into develop
Browse files Browse the repository at this point in the history
Forward port #216
  • Loading branch information
weierophinney committed Dec 11, 2018
2 parents a973a0f + bf1494c commit 286c8be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#216](https://github.com/zendframework/zend-form/pull/216) fixes an issue when performing data binding and a fieldset has no mapped
input elements, casting `null` values to empty arrays to ensure they can be
passed to an input filter.

- [#207](https://github.com/zendframework/zend-form/pull/207) fixes the return value annotation for the `Fieldset::get()` method to
indicate it can also return a `FieldsetInterface` instance.

Expand Down
4 changes: 3 additions & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ public function bindValues(array $values = [], array $validationGroup = null)

// If there is a base fieldset, only hydrate beginning from the base fieldset
if ($this->baseFieldset !== null) {
$data = $data[$this->baseFieldset->getName()];
$data = array_key_exists($this->baseFieldset->getName(), $data)
? $data[$this->baseFieldset->getName()]
: [];
$this->object = $this->baseFieldset->bindValues($data, $validationGroup[$this->baseFieldset->getName()]);
} else {
$this->object = parent::bindValues($data, $validationGroup);
Expand Down
26 changes: 24 additions & 2 deletions test/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Zend\Form\Factory;
use Zend\Form\Fieldset;
use Zend\Form\Form;
use Zend\Hydrator;
use Zend\Hydrator\ObjectProperty as ObjectPropertyHydrator;
use Zend\InputFilter\BaseInputFilter;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFilterFactory;
use Zend\Hydrator;
use Zend\InputFilter\InputFilter;
use ZendTest\Form\TestAsset\Entity;
use ZendTest\Form\TestAsset\HydratorAwareModel;

Expand Down Expand Up @@ -818,6 +818,28 @@ public function testBindValuesWithWrappingPopulatesBoundObject()
], $model->foobar);
}

public function testFormBaseFieldsetBindValuesWithoutInputs()
{
$baseFieldset = new Fieldset('base_fieldset');
$baseFieldset->setUseAsBaseFieldset(true);

$form = new Form();
$form->add($baseFieldset);
$form->setHydrator(new ObjectPropertyHydrator());

$model = new stdClass();
$form->bind($model);

$data = [
'submit' => 'save',
];
$form->setData($data);

$form->isValid(); // Calls ->bindValues after validation (line: 817)

$this->assertObjectNotHasAttribute('submit', $model);
}

public function testHasFactoryComposedByDefault()
{
$factory = $this->form->getFormFactory();
Expand Down

0 comments on commit 286c8be

Please sign in to comment.