From f07dce4604546c70f1b298bfe7da873bf94ecda9 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Tue, 16 Nov 2021 23:27:29 +0000 Subject: [PATCH] [UTIL][Form] Fix bug with repeated_password --- src/Util/Form/FormFields.php | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Util/Form/FormFields.php b/src/Util/Form/FormFields.php index ca1dbee637..ba6c867ae1 100644 --- a/src/Util/Form/FormFields.php +++ b/src/Util/Form/FormFields.php @@ -1,10 +1,9 @@ _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')]), ]), - ] : []; + $constraints = (array_key_exists('required', $options) && $options['required'] === false) ? [] + : [ + 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')]),]), + ]; return [ 'password', RepeatedType::class, [ - 'type' => PasswordType::class, + 'type' => PasswordType::class, 'first_options' => [ - 'label' => _m('Password'), - 'label_attr' => ['class' => 'section-form-label'], - 'attr' => ['placeholder' => _m('********'), 'required' => $options['required'] ?? true], + 'label' => _m('Password'), + 'label_attr' => ['class' => 'section-form-label'], + 'attr' => ['placeholder' => _m('********'), 'required' => $options['required'] ?? true], 'constraints' => $constraints, - 'help' => _m('Write a password with at least {min_length} characters, and a maximum of {max_length}.', ['min_length' => Common::config('password', 'min_length'), 'max_length' => Common::config('password', 'max_length')]), + 'help' => _m('Write a password with at least {min_length} characters, and a maximum of {max_length}.', ['min_length' => Common::config('password', 'min_length'), 'max_length' => Common::config('password', 'max_length')]), ], 'second_options' => [ - 'label' => _m('Repeat Password'), - 'label_attr' => ['class' => 'section-form-label'], - 'attr' => ['placeholder' => _m('********')], - 'help' => _m('Confirm your password.'), - 'required' => $options['required'] ?? true, + 'label' => _m('Repeat Password'), + 'label_attr' => ['class' => 'section-form-label'], + 'attr' => ['placeholder' => _m('********')], + 'help' => _m('Confirm your password.'), + 'required' => $options['required'] ?? true, 'constraints' => $constraints, ], - 'mapped' => false, - 'required' => $options['required'] ?? true, + 'mapped' => false, + 'required' => $options['required'] ?? true, 'invalid_message' => _m('The password fields must match'), ], ]; @@ -58,16 +58,16 @@ abstract class FormFields { return [ 'password', PasswordType::class, [ - 'label' => _m('Password'), - 'label_attr' => ['class' => 'section-form-label'], - 'attr' => ['placeholder' => '********'], - 'required' => $options['required'] ?? true, - 'mapped' => false, + 'label' => _m('Password'), + 'label_attr' => ['class' => 'section-form-label'], + 'attr' => ['placeholder' => '********'], + 'required' => $options['required'] ?? true, + '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')]), ]), - ], ], + 'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_length')]),]), + ],], ]; } @@ -78,12 +78,12 @@ abstract class FormFields 'language' . ($multiple ? 's' : ''), ChoiceType::class, [ - 'label' => _m($label), + 'label' => _m($label), 'preferred_choices' => $preferred_language_choices, - 'choices' => $language_choices, - 'required' => $required, - 'multiple' => $multiple, - 'help' => _m($help), + 'choices' => $language_choices, + 'required' => $required, + 'multiple' => $multiple, + 'help' => _m($help), ], ]; }