src/Form/ChangePasswordFormType.php line 14
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
class ChangePasswordFormType extends AbstractType
{
public function __construct(private TranslatorInterface $translator)
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'label'=>$this->translator->trans('Password'),
'first_options' => [
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-control mb-4'],
'constraints' => [
new NotBlank([
'message' => $this->translator->trans('Veuillez entrer un mot de passe'),
]),
new Length([
'min' => 6,
'minMessage' => $this->translator->trans('Votre mot de passe doit comporter au moins {{ limit }} caractères'),
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'label' => $this->translator->trans('Nouveau mot de passe'),
],
'second_options' => [
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-control'],
'label' => $this->translator->trans('Répéter le mot de passe'),
],
'invalid_message' => $this->translator->trans('Les champs du mot de passe doivent correspondre.'),
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([]);
}
}