[UTIL][FORM] Create a utility class that defines common form fields, such as passwords

This commit is contained in:
Hugo Sales 2021-08-03 10:24:45 +00:00
parent dfc97d2607
commit 855d427442
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -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')]), ]),
], ],
];
}
}