Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UserCrudController | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
getEntityFqcn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
configureFields | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Controller\Admin; |
4 | |
5 | use App\Entity\User; |
6 | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
7 | use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; |
8 | use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; |
9 | use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; |
10 | use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; |
11 | use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField; |
12 | use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
13 | use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
14 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
15 | |
16 | class UserCrudController extends AbstractCrudController |
17 | { |
18 | public static function getEntityFqcn(): string |
19 | { |
20 | return User::class; |
21 | } |
22 | |
23 | public function configureFields(string $pageName): iterable |
24 | { |
25 | $roles = ['ROLE_FOUNDER', 'ROLE_ADMIN', 'ROLE_MODERATOR', 'ROLE_USER']; |
26 | |
27 | yield IdField::new(propertyName: 'id') |
28 | ->onlyOnIndex(); |
29 | yield TextField::new(propertyName: 'firstName'); |
30 | yield TextField::new(propertyName: 'lastName'); |
31 | yield EmailField::new(propertyName: 'email'); |
32 | yield TextField::new('password') |
33 | ->setFormType(RepeatedType::class) |
34 | ->setFormTypeOptions([ |
35 | 'type' => PasswordType::class, |
36 | 'first_options' => ['label' => 'Password'], |
37 | 'second_options' => ['label' => 'Password (Repeat)'], |
38 | 'mapped' => false, |
39 | ]) |
40 | ->setRequired($pageName === Crud::PAGE_NEW) |
41 | ->onlyOnForms(); |
42 | yield ImageField::new(propertyName: 'avatar') |
43 | ->setBasePath(path: 'uploads/avatars') |
44 | ->setUploadDir(uploadDirPath: 'public/uploads/avatars') |
45 | ->setUploadedFileNamePattern(patternOrCallable: '[slug]-[timestamp].[extension]'); |
46 | yield ChoiceField::new(propertyName: 'roles') |
47 | ->setChoices(choiceGenerator: array_combine(keys: $roles, values: $roles)) |
48 | ->allowMultipleChoices() |
49 | ->renderExpanded() |
50 | ->renderAsBadges(); |
51 | } |
52 | } |