Skip to content

Commit 3f7b37d

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Form] Fixed keeping hash of equal \DateTimeInterface on submit [PhpUnitBridge] Fix typo [Config] Unset key during normalization invalidate forms on transformation failures
2 parents 490695a + 65384ce commit 3f7b37d

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Definition/ArrayNode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ protected function normalizeValue($value)
292292
$normalized = array();
293293
foreach ($value as $name => $val) {
294294
if (isset($this->children[$name])) {
295-
$normalized[$name] = $this->children[$name]->normalize($val);
295+
try {
296+
$normalized[$name] = $this->children[$name]->normalize($val);
297+
} catch (UnsetKeyException $e) {
298+
}
296299
unset($value[$name]);
297300
} elseif (!$this->removeExtraKeys) {
298301
$normalized[$name] = $val;

Definition/Builder/ExprBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function thenEmptyArray()
174174
}
175175

176176
/**
177-
* Sets a closure marking the value as invalid at validation time.
177+
* Sets a closure marking the value as invalid at processing time.
178178
*
179179
* if you want to add the value of the node in your message just use a %s placeholder.
180180
*
@@ -192,7 +192,7 @@ public function thenInvalid($message)
192192
}
193193

194194
/**
195-
* Sets a closure unsetting this key of the array at validation time.
195+
* Sets a closure unsetting this key of the array at processing time.
196196
*
197197
* @return $this
198198
*

Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ public function testNormalizeKeys()
231231
$this->assertFalse($this->getField($node, 'normalizeKeys'));
232232
}
233233

234+
public function testUnsetChild()
235+
{
236+
$node = new ArrayNodeDefinition('root');
237+
$node
238+
->children()
239+
->scalarNode('value')
240+
->beforeNormalization()
241+
->ifTrue(function ($value) {
242+
return empty($value);
243+
})
244+
->thenUnset()
245+
->end()
246+
->end()
247+
->end()
248+
;
249+
250+
$this->assertSame(array(), $node->getNode()->normalize(array('value' => null)));
251+
}
252+
234253
public function testPrototypeVariable()
235254
{
236255
$node = new ArrayNodeDefinition('root');

0 commit comments

Comments
 (0)