make NotBlank error messages translatable in LoginForm

This commit is contained in:
Kevin Pfeifer
2020-10-15 22:52:25 +02:00
parent 99249a5394
commit 9784e877ea
2 changed files with 24 additions and 4 deletions
+12 -4
View File
@@ -12,14 +12,20 @@ namespace Bolt\Form;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
class LoginType extends AbstractType
{
public $authenticationUtils;
/** @var AuthenticationUtils */
private $authenticationUtils;
public function __construct(AuthenticationUtils $authenticationUtils)
/** @var TranslatorInterface */
private $translator;
public function __construct(AuthenticationUtils $authenticationUtils, TranslatorInterface $translator)
{
$this->authenticationUtils = $authenticationUtils;
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
@@ -34,24 +40,26 @@ namespace Bolt\Form;
'label' => 'label.username_or_email',
'constraints' => [
new NotBlank([
'message' => 'Please enter your username or email',
'message' => $this->translator->trans('form.empty_username_email'),
]),
],
'attr' => [
'placeholder' => 'placeholder.username_or_email',
],
'data' => $last_username,
'required' => false
])
->add('password', PasswordType::class, [
'label' => 'label.password',
'constraints' => [
new NotBlank([
'message' => 'Please enter your password',
'message' => $this->translator->trans('form.empty_password'),
]),
],
'attr' => [
'placeholder' => 'placeholder.password',
],
'required' => false
]);
}
+12
View File
@@ -2373,5 +2373,17 @@
<target>Select …</target>
</segment>
</unit>
<unit id="2SSLP1K" name="form.empty_username_email">
<segment>
<source>form.empty_username_email</source>
<target>Please enter your username or email</target>
</segment>
</unit>
<unit id="5Qf_RiO" name="form.empty_password">
<segment>
<source>form.empty_password</source>
<target>Please enter your password</target>
</segment>
</unit>
</file>
</xliff>