Skip to content

Commit

Permalink
keep the context when validating forms
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jan 26, 2018
1 parent 4f47bb7 commit 317da3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 317da3b

Please sign in to comment.