From 0c54a3297f5b8372ccaadcf446881aac821b2e4a Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 29 Jul 2021 17:27:01 +0000 Subject: [PATCH] [UTIL] Add a class that defines commonly used form fields --- src/Controller/Security.php | 11 +---------- src/Util/FormFields.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/Util/FormFields.php diff --git a/src/Controller/Security.php b/src/Controller/Security.php index 0d95337e76..cdd02d0a61 100644 --- a/src/Controller/Security.php +++ b/src/Controller/Security.php @@ -20,7 +20,6 @@ use App\Util\Exception\ServerException; use App\Util\Nickname; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Symfony\Component\Form\Extension\Core\Type\EmailType; -use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; @@ -85,15 +84,7 @@ class Security extends Controller 'label' => _m('Email'), 'constraints' => [ new NotBlank(['message' => _m('Please enter an email') ])], ]], - ['password', PasswordType::class, [ - 'label' => _m('Password'), - 'mapped' => false, - 'constraints' => [ - new NotBlank(['message' => _m('Please enter a password')]), - new Length(['min' => Common::config('password', 'min_length'), 'minMessage' => _m(['Your password should be at least # characters'], ['count' => Common::config('password', 'min_length')]), - 'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_length')]), ]), - ], - ]], + FormFields::password(), ['register', SubmitType::class, ['label' => _m('Register')]], ]); diff --git a/src/Util/FormFields.php b/src/Util/FormFields.php new file mode 100644 index 0000000000..be66ece224 --- /dev/null +++ b/src/Util/FormFields.php @@ -0,0 +1,30 @@ + PasswordType::class, + 'first_options' => [ + 'label' => _m('Password'), + 'constraints' => [ + new NotBlank(['message' => _m('Please enter a password')]), + new Length(['min' => Common::config('password', 'min_length'), 'minMessage' => _m(['Your password should be at least # characters'], ['count' => Common::config('password', 'min_length')]), + 'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_length')]), ]), + ], + ], + 'second_options' => [ + 'label' => _m('Repeat Password'), + ], + 'mapped' => false, + 'invalid_message' => _m('The password fields must match'), + ], + ]; + } +}