-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAclRoleFormTrait.php
More file actions
76 lines (62 loc) · 1.82 KB
/
Copy pathAclRoleFormTrait.php
File metadata and controls
76 lines (62 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace ADT\FancyAdmin\UI\Components\Forms\AclRole;
use ADT\FancyAdmin\DI\Injects\EntityManagerInject;
use ADT\FancyAdmin\DI\Injects\AclRoleQueryFactoryInject;
use ADT\FancyAdmin\DI\Injects\FancyAdminInject;
use ADT\FancyAdmin\Model\Entities\AclRole;
use ADT\FancyAdmin\Model\Entities\Enums\AclRoleTypeEnum;
use ADT\Forms\Form;
use Exception;
/**
* @property AclRole $entity
*/
trait AclRoleFormTrait
{
use EntityManagerInject;
use AclRoleQueryFactoryInject;
use FancyAdminInject;
/**
* @throws Exception
*/
public function initForm(Form $form): void
{
$form->addText('name', 'fcadmin.forms.aclRole.name')
->setRequired();
$form->addSelect('type', 'fcadmin.forms.aclRole.type', [
AclRoleTypeEnum::IDENTITY->value => 'fcadmin.forms.aclRole.types.identity',
AclRoleTypeEnum::PROFILE->value => 'fcadmin.forms.aclRole.types.profile',
])
->setRequired();
$form->addCheckbox('isAdmin', 'fcadmin.forms.aclRole.isAdmin');
if ($this->_fancyAdmin->isKeycloakEnabled()) {
$form->addCheckbox('needsSso', 'fcadmin.forms.aclRole.needsSso');
}
$form->addSubmit('submit', 'fcadmin.forms.aclRole.submit');
}
protected function getEntityClass(): ?string
{
return $this->_em->findEntityClassByInterface(AclRole::class);
}
public function validateForm(?AclRole $entity, array $inputs, Form $form): void
{
$query = $this->_aclRoleQueryFactory->create()
->disableSecurityFilter()
->byName($inputs['name']);
if ($entity && !$entity->isNew()) {
$query->byIdNot($entity->getId());
}
if ($query->fetch()) {
$form['name']->addError('fcadmin.forms.aclRole.errors.nameAlreadyExists');
}
}
/**
* @throws Exception
*/
public function processForm(AclRole $entity): void
{
if ($entity->isNew()) {
$entity->setContext($this->_fancyAdmin->getContext());
}
$this->em->flush();
}
}