8000 minor #58187 Pass `validator.translation_domain` to `RequestPayloadVa… · symfony/symfony@a138360 · GitHub
[go: up one dir, main page]

Skip to content

Commit a138360

Browse files
minor #58187 Pass validator.translation_domain to RequestPayloadValueResolver (raphael-geffroy)
This PR was merged into the 7.2 branch. Discussion ---------- Pass `validator.translation_domain` to `RequestPayloadValueResolver` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #58170 | License | MIT Replaces hardcoded validation translation domain by container param `validator.translation_domain`. Used [UploadValidatorExtension](https://github.com/symfony/symfony/blob/7f15676de99eae53b5b818a038b1bf070577b341/src/Symfony/Component/Form/Extension/Validator/Type/UploadValidatorExtension.php#L24) as inspiration. Commits ------- 2d45107 fix: pass validator.translation_domain to RequestPayloadValueResolver
2 parents b19a108 + 2d45107 commit a138360

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
service('serializer'),
7272
service('validator')->nullOnInvalid(),
7373
service('translator')->nullOnInvalid(),
74+
param('validator.translation_domain'),
7475
])
7576
->tag('controller.targeted_value_resolver', ['name' => RequestPayloadValueResolver::class])
7677
->tag('kernel.event_subscriber')

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function __construct(
6565
private readonly SerializerInterface&DenormalizerInterface $serializer,
6666
private readonly ?ValidatorInterface $validator = null,
6767
private readonly ?TranslatorInterface $translator = null,
68+
private string $translationDomain = 'validators',
6869
) {
6970
}
7071

@@ -137,7 +138,7 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
137138
if ($error->canUseMessageForUser()) {
138139
$parameters['hint'] = $error->getMessage();
139140
}
140-
$message = $trans($template, $parameters, 'validators');
141+
$message = $trans($template, $parameters, $this->translationDomain);
141142
$violations->add(new ConstraintViolation($message, $template, $parameters, null, $error->getPath(), null));
142143
}
143144
$payload = $e->getData();

0 commit comments

Comments
 (0)
0