From fe755f7c42091266ff17967a20ab8f9872476338 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 15 Nov 2021 19:32:14 +0000 Subject: [PATCH] [UTIL][FormFields] Accomodate use of FormFields::repeated_password without a 'required' option --- src/Util/Form/FormFields.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Util/Form/FormFields.php b/src/Util/Form/FormFields.php index ba6c867ae1..74070af995 100644 --- a/src/Util/Form/FormFields.php +++ b/src/Util/Form/FormFields.php @@ -18,12 +18,13 @@ abstract class FormFields { public static function repeated_password(array $options = []): array { - $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')]),]), - ]; + $constraints = ($options['required'] ?? true) + ? [ + 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,