From 335ca5e5ef9f078296a4ababa321a19b6c01156a Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 22 Nov 2022 13:53:21 +0100 Subject: [PATCH] added password field --- src/Controller/Admin/UserCrudController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Controller/Admin/UserCrudController.php b/src/Controller/Admin/UserCrudController.php index 4efae24..db24c5f 100644 --- a/src/Controller/Admin/UserCrudController.php +++ b/src/Controller/Admin/UserCrudController.php @@ -3,12 +3,15 @@ namespace App\Controller\Admin; use App\Entity\User; +use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\RepeatedType; class UserCrudController extends AbstractCrudController { @@ -19,16 +22,27 @@ class UserCrudController extends AbstractCrudController public function configureFields(string $pageName): iterable { + $roles = ['ROLE_FOUNDER', 'ROLE_ADMIN', 'ROLE_MODERATOR', 'ROLE_USER']; + yield IdField::new(propertyName: 'id') ->onlyOnIndex(); yield TextField::new(propertyName: 'firstName'); yield TextField::new(propertyName: 'lastName'); yield EmailField::new(propertyName: 'email'); + yield TextField::new('password') + ->setFormType(RepeatedType::class) + ->setFormTypeOptions([ + 'type' => PasswordType::class, + 'first_options' => ['label' => 'Password'], + 'second_options' => ['label' => 'Password (Repeat)'], + 'mapped' => false, + ]) + ->setRequired($pageName === Crud::PAGE_NEW) + ->onlyOnForms(); yield ImageField::new(propertyName: 'avatar') ->setBasePath(path: 'uploads/avatars') ->setUploadDir(uploadDirPath: 'public/uploads/avatars') ->setUploadedFileNamePattern(patternOrCallable: '[slug]-[timestamp].[extension]'); - $roles = ['ROLE_FOUNDER', 'ROLE_ADMIN', 'ROLE_MODERATOR', 'ROLE_USER']; yield ChoiceField::new(propertyName: 'roles') ->setChoices(choiceGenerator: array_combine(keys: $roles, values: $roles)) ->allowMultipleChoices()