[UTIL][FormFields] Accomodate use of FormFields::repeated_password without a 'required' option

This commit is contained in:
Hugo Sales 2021-11-15 19:32:14 +00:00
parent 1dd86a2302
commit fe755f7c42
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 7 additions and 6 deletions

View File

@ -18,12 +18,13 @@ abstract class FormFields
{ {
public static function repeated_password(array $options = []): array public static function repeated_password(array $options = []): array
{ {
$constraints = (array_key_exists('required', $options) && $options['required'] === false) ? [] $constraints = ($options['required'] ?? true)
: [ ? [
new NotBlank(['message' => _m('Please enter a password')]), 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')]), new Length([
'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_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 [ return [
'password', RepeatedType::class, 'password', RepeatedType::class,