8000 [Form] Make form submission requirement optional · symfony/symfony@0f9fd9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f9fd9b

Browse files
author
Brandon Woodmansee
committed
[Form] Make form submission requirement optional
1 parent 9500411 commit 0f9fd9b

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class ViolationMapper implements ViolationMapperInterface
2929
*/
3030
private $allowNonSynchronized;
3131

32+
/**
33+
* @var bool
34+
*/
35+
private $formSubmissionRequired = true;
36+
3237
/**
3338
* {@inheritdoc}
3439
*/
@@ -292,9 +297,29 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
292297
*/
293298
private function acceptsErrors(FormInterface $form)
294299
{
295-
// Ignore non-submitted forms. This happens, for example, in PATCH
296-
// requests.
297-
// https://github.com/symfony/symfony/pull/10567
298-
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
300+
if ($this->isFormSubmissionRequired()) {
301+
// Ignore non-submitted forms. This happens, for example, in PATCH
302+
// requests.
303+
// https://github.com/symfony/symfony/pull/10567
304+
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
305+
}
306+
307+
return $this->allowNonSynchronized || $form->isSynchronized();
308+
}
309+
310+
/**
311+
* @param bool $formSubmissionRequired
312+
*/
313+
public function setFormSubmissionRequired($formSubmissionRequired)
314+
{
315+
$this->formSubmissionRequired = (bool) $formSubmissionRequired;
316+
}
317+
318+
/**
319+
* @return bool
320+
*/
321+
private function isFormSubmissionRequired()
322+
{
323+
return $this->formSubmissionRequired;
299324
}
300325
}

0 commit comments

Comments
 (0)
0