Skip to content

Commit b739919

Browse files
committed
Remove translator dependency
1 parent 64ef743 commit b739919

File tree

2 files changed

+1
-19
lines changed

2 files changed

+1
-19
lines changed

Resources/config/serializer.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
<!-- Normalizes FormInterface when using the symfony serializer -->
1818
<service id="fos_rest.serializer.form_error_normalizer" class="FOS\RestBundle\Serializer\Normalizer\FormErrorNormalizer" public="false">
19-
<argument type="service" id="translator" />
2019
<tag name="serializer.normalizer" priority="-10" />
2120
</service>
2221
</services>

Serializer/Normalizer/FormErrorNormalizer.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Form\FormError;
1515
use Symfony\Component\Form\FormInterface;
1616
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17-
use Symfony\Component\Translation\TranslatorInterface;
1817

1918
/**
2019
* Normalizes invalid Form instances.
@@ -23,13 +22,6 @@
2322
*/
2423
class FormErrorNormalizer implements NormalizerInterface
2524
{
26-
private $translator;
27-
28-
public function __construct(TranslatorInterface $translator)
29-
{
30-
$this->translator = $translator;
31-
}
32-
3325
/**
3426
* {@inheritdoc}
3527
*/
@@ -58,7 +50,7 @@ private function convertFormToArray(FormInterface $data)
5850
$form = $errors = [];
5951

6052
foreach ($data->getErrors() as $error) {
61-
$errors[] = $this->getErrorMessage($error);
53+
$errors[] = $error->getMessage();
6254
}
6355

6456
if ($errors) {
@@ -78,13 +70,4 @@ private function convertFormToArray(FormInterface $data)
7870

7971
return $form;
8072
}
81-
82-
private function getErrorMessage(FormError $error)
83-
{
84-
if (null !== $error->getMessagePluralization()) {
85-
return $this->translator->transChoice($error->getMessageTemplate(), $error->getMessagePluralization(), $error->getMessageParameters(), 'validators');
86-
}
87-
88-
return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators');
89-
}
9073
}

0 commit comments

Comments
 (0)