From 855d42744230f319689ed8700726e18ed0ca576e Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 3 Aug 2021 10:24:45 +0000 Subject: [PATCH] [UTIL][FORM] Create a utility class that defines common form fields, such as passwords --- src/Util/FormFields.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Util/FormFields.php b/src/Util/FormFields.php index be66ece224..584fd8ff58 100644 --- a/src/Util/FormFields.php +++ b/src/Util/FormFields.php @@ -2,12 +2,15 @@ namespace App\Util; +use function App\Core\I18n\_m; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType; +use Symfony\Component\Validator\Constraints\Length; +use Symfony\Component\Validator\Constraints\NotBlank; abstract class FormFields { - public static function password() + public static function repeated_password() { return ['password', RepeatedType::class, ['type' => PasswordType::class, @@ -27,4 +30,17 @@ abstract class FormFields ], ]; } + + public static function password() + { + ['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')]), ]), + ], ], + ]; + } }