8000 Revert "bug #18935 [Form] Consider a violation even if the form is no… · symfony/symfony@bcb1d8f · GitHub
[go: up one dir, main page]

Skip to content

Commit bcb1d8f

Browse files
committed
Revert "bug #18935 [Form] Consider a violation even if the form is not submitted (egeloen)"
This reverts commit f28eb9a, reversing changes made to bbb75fa.
1 parent e4b48bb commit bcb1d8f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
275275
*/
276276
private function acceptsErrors(FormInterface $form)
277277
{
278-
return $this->allowNonSynchronized || $form->isSynchronized();
278+
// Ignore non-submitted forms. This happens, for example, in PATCH
279+
// requests.
280+
// https://github.com/symfony/symfony/pull/10567
281+
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
279282
}
280283
}

src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function testAbortDotRuleMappingIfNotSynchronized()
212212
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
213213
}
214214

215-
public function testMappingIfNotSubmitted()
215+
public function testAbortMappingIfNotSubmitted()
216216
{
217217
$violation = $this->getConstraintViolation('children[address].data.street');
218218
$parent = $this->getForm('parent');
@@ -230,12 +230,12 @@ public function testMappingIfNotSubmitted()
230230

231231
$this->mapper->mapViolation($violation, $parent);
232232

233-
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error');
234-
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error');
235-
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have one error');
233+
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
234+
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
235+
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
236236
}
237237

238-
public function testDotRuleMappingIfNotSubmitted()
238+
public function testAbortDotRuleMappingIfNotSubmitted()
239239
{
240240
$violation = $this->getConstraintViolation('data.address');
241241
$parent = $this->getForm('parent');
@@ -255,9 +255,9 @@ public function testDotRuleMappingIfNotSubmitted()
255255

256256
$this->mapper->mapViolation($violation, $parent);
257257

258-
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error');
259-
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error');
260-
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have an error');
258+
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
259+
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
260+
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
261261
}
262262

263263
public function provideDefaultTests()

0 commit comments

Comments
 (0)
0