fix translating file validation error message
This commit is contained in:
parent
62e5a91150
commit
9c41842756
@ -93,7 +93,7 @@
|
|||||||
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
|
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
|
||||||
</service>
|
</service>
|
||||||
<service id="form.type.file" class="Symfony\Component\Form\Extension\Core\Type\FileType" public="true">
|
<service id="form.type.file" class="Symfony\Component\Form\Extension\Core\Type\FileType" public="true">
|
||||||
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
|
<argument type="service" id="translator" on-invalid="ignore" />
|
||||||
</service>
|
</service>
|
||||||
<service id="form.type.hidden" class="Symfony\Component\Form\Extension\Core\Type\HiddenType" public="true">
|
<service id="form.type.hidden" class="Symfony\Component\Form\Extension\Core\Type\HiddenType" public="true">
|
||||||
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
|
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
|
||||||
|
@ -20,6 +20,7 @@ use Symfony\Component\Form\FormInterface;
|
|||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\OptionsResolver\Options;
|
use Symfony\Component\OptionsResolver\Options;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class FileType extends AbstractType
|
class FileType extends AbstractType
|
||||||
{
|
{
|
||||||
@ -32,6 +33,13 @@ class FileType extends AbstractType
|
|||||||
self::MIB_BYTES => 'MiB',
|
self::MIB_BYTES => 'MiB',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private $translator;
|
||||||
|
|
||||||
|
public function __construct(TranslatorInterface $translator = null)
|
||||||
|
{
|
||||||
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -150,7 +158,13 @@ class FileType extends AbstractType
|
|||||||
$messageTemplate = 'The file could not be uploaded.';
|
$messageTemplate = 'The file could not be uploaded.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FormError($messageTemplate, $messageTemplate, $messageParameters);
|
if (null !== $this->translator) {
|
||||||
|
$message = $this->translator->trans($messageTemplate, $messageParameters);
|
||||||
|
} else {
|
||||||
|
$message = strtr($messageTemplate, $messageParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FormError($message, $messageTemplate, $messageParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user