Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c41842

Browse filesBrowse files
committed
fix translating file validation error message
1 parent 62e5a91 commit 9c41842
Copy full SHA for 9c41842

File tree

Expand file treeCollapse file tree

2 files changed

+16
-2
lines changed
Filter options
  • src/Symfony
Expand file treeCollapse file tree

2 files changed

+16
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
9494
</service>
9595
<service id="form.type.file" class="Symfony\Component\Form\Extension\Core\Type\FileType" public="true">
96-
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>
96+
<argument type="service" id="translator" on-invalid="ignore" />
9797
</service>
9898
<service id="form.type.hidden" class="Symfony\Component\Form\Extension\Core\Type\HiddenType" public="true">
9999
<deprecated>The "%service_id%" service is deprecated since Symfony 3.1 and will be removed in 4.0.</deprecated>

‎src/Symfony/Component/Form/Extension/Core/Type/FileType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FileType.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Form\FormView;
2121
use Symfony\Component\OptionsResolver\Options;
2222
use Symfony\Component\OptionsResolver\OptionsResolver;
23+
use Symfony\Component\Translation\TranslatorInterface;
2324

2425
class FileType extends AbstractType
2526
{
@@ -32,6 +33,13 @@ class FileType extends AbstractType
3233
self::MIB_BYTES => 'MiB',
3334
];
3435

36+
private $translator;
37+
38+
public function __construct(TranslatorInterface $translator = null)
39+
{
40+
$this->translator = $translator;
41+
}
42+
3543
/**
3644
* {@inheritdoc}
3745
*/
@@ -150,7 +158,13 @@ private function getFileUploadError($errorCode)
150158
$messageTemplate = 'The file could not be uploaded.';
151159
}
152160

153-
return new FormError($messageTemplate, $messageTemplate, $messageParameters);
161+
if (null !== $this->translator) {
162+
$message = $this->translator->trans($messageTemplate, $messageParameters);
163+
} else {
164+
$message = strtr($messageTemplate, $messageParameters);
165+
}
166+
167+
return new FormError($message, $messageTemplate, $messageParameters);
154168
}
155169

156170
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.