Skip to content

Commit 56b6ed7

Browse files
committed
Container::getValues('array') propagates arrays to inner containers only when mappedType is not set
1 parent dd11397 commit 56b6ed7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Forms/Container.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
3838
/** @var bool */
3939
private $validated;
4040

41-
/** @var string */
42-
private $mappedType = ArrayHash::class;
41+
/** @var ?string */
42+
private $mappedType;
4343

4444

4545
/********************* data exchange ****************d*g**/
@@ -109,7 +109,7 @@ public function getValues($returnType = null)
109109
{
110110
$returnType = $returnType
111111
? ($returnType === true ? self::ARRAY : $returnType) // back compatibility
112-
: $this->mappedType;
112+
: ($this->mappedType ?? ArrayHash::class);
113113

114114
$isArray = $returnType === self::ARRAY;
115115
$obj = $isArray ? new \stdClass : new $returnType;
@@ -118,7 +118,7 @@ public function getValues($returnType = null)
118118
if ($control instanceof IControl && !$control->isOmitted()) {
119119
$obj->$name = $control->getValue();
120120
} elseif ($control instanceof self) {
121-
$obj->$name = $control->getValues($isArray ? self::ARRAY : null);
121+
$obj->$name = $control->getValues($isArray && !$control->mappedType ? self::ARRAY : null);
122122
}
123123
}
124124
return $isArray ? (array) $obj : $obj;

tests/Forms/Container.values.mapping.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ test(function () { // getValues(...arguments...)
238238

239239
Assert::equal([
240240
'title' => 'new1',
241-
'first' => [
241+
'first' => hydrate(FormFirstLevel::class, [
242242
'name' => 'new2',
243243
'age' => null,
244-
'second' => [
244+
'second' => hydrate(FormSecondLevel::class, [
245245
'city' => '',
246-
],
247-
],
246+
]),
247+
]),
248248
], $form->getValues(true));
249249
});
250250

0 commit comments

Comments
 (0)