bug #25940 [Form] keep the context when validating forms (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] keep the context when validating forms
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25542
| License | MIT
| Doc PR |
Commits
-------
317da3bdf8
keep the context when validating forms
This commit is contained in:
commit
12447d972f
@ -124,6 +124,7 @@ class FormValidator extends ConstraintValidator
|
|||||||
: gettype($form->getViewData());
|
: gettype($form->getViewData());
|
||||||
|
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
|
$this->context->setConstraint($constraint);
|
||||||
$this->context->buildViolation($config->getOption('invalid_message'))
|
$this->context->buildViolation($config->getOption('invalid_message'))
|
||||||
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
|
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
|
||||||
->setInvalidValue($form->getViewData())
|
->setInvalidValue($form->getViewData())
|
||||||
@ -144,6 +145,7 @@ class FormValidator extends ConstraintValidator
|
|||||||
// Mark the form with an error if it contains extra fields
|
// Mark the form with an error if it contains extra fields
|
||||||
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
|
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
|
$this->context->setConstraint($constraint);
|
||||||
$this->context->buildViolation($config->getOption('extra_fields_message'))
|
$this->context->buildViolation($config->getOption('extra_fields_message'))
|
||||||
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
|
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
|
||||||
->setInvalidValue($form->getExtraData())
|
->setInvalidValue($form->getExtraData())
|
||||||
|
@ -51,6 +51,8 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();
|
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->constraint = new Form();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getApiVersion()
|
protected function getApiVersion()
|
||||||
|
Reference in New Issue
Block a user