Skip to content

Commit

Permalink
bug #25940 [Form] keep the context when validating forms (xabbuh)
Browse files Browse the repository at this point in the history
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
-------

317da3b keep the context when validating forms
  • Loading branch information
fabpot committed Feb 7, 2018
2 parents 7ac5447 + 317da3b commit 12447d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Expand Up @@ -124,6 +124,7 @@ public function validate($form, Constraint $constraint)
: gettype($form->getViewData());

if ($this->context instanceof ExecutionContextInterface) {
$this->context->setConstraint($constraint);
$this->context->buildViolation($config->getOption('invalid_message'))
->setParameters(array_replace(array('{{ value }}' => $clientDataAsString), $config->getOption('invalid_message_parameters')))
->setInvalidValue($form->getViewData())
Expand All @@ -144,6 +145,7 @@ public function validate($form, Constraint $constraint)
// Mark the form with an error if it contains extra fields
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->setConstraint($constraint);
$this->context->buildViolation($config->getOption('extra_fields_message'))
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
->setInvalidValue($form->getExtraData())
Expand Down
Expand Up @@ -51,6 +51,8 @@ protected function setUp()
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\Util\ServerParams')->setMethods(array('getNormalizedIniPostMaxSize', 'getContentLength'))->getMock();

parent::setUp();

$this->constraint = new Form();
}

protected function getApiVersion()
Expand Down

0 comments on commit 12447d9

Please sign in to comment.