-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileFormTrait.php
More file actions
72 lines (64 loc) · 1.95 KB
/
Copy pathProfileFormTrait.php
File metadata and controls
72 lines (64 loc) · 1.95 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
<?php
namespace ADT\FancyAdmin\UI\Components\Forms\Profile;
use ADT\DoctrineComponents\Entities\Entity;
use ADT\DoctrineForms\Form;
use ADT\FancyAdmin\DI\Injects\EntityManagerInject;
use ADT\FancyAdmin\DI\Injects\IdentityQueryFactoryInject;
use ADT\FancyAdmin\DI\Injects\SecurityUserInject;
use ADT\FancyAdmin\Model\Entities\Identity;
use ADT\FancyAdmin\Model\Entities\Profile;
use ADT\FancyAdmin\UI\Components\Forms\IdentityProfileFormTrait;
use Contributte\Translation\Exceptions\InvalidArgument;
use Exception;
use Nette\Application\UI\InvalidLinkException;
trait ProfileFormTrait
{
use SecurityUserInject;
use IdentityProfileFormTrait;
use EntityManagerInject;
use IdentityQueryFactoryInject;
/**
* @throws Exception
*/
public function initForm(Form $form, ?Profile $profile): void
{
$this->addFormFields($form, $profile, isProfile: true);
}
/**
* @throws \DateMalformedStringException
* @throws InvalidArgument
* @throws InvalidLinkException
* @throws \Doctrine\DBAL\Exception|\ReflectionException
*/
public function processForm(Profile $profile): void
{
$this->processUserForm($profile->getIdentity());
}
protected function getEntityClass(): ?string
{
return $this->_em->findEntityClassByInterface(Profile::class);
}
/**
* @param Profile $entity
* @param array $values
* @return void
*/
protected function initEntity(Entity $entity, array $values): void
{
if (
!isset($values['identity']['email'])
||
(!$identity = $this->_identityQueryFactory->create()->disableSecurityFilter()->disableAccountFilter()->byContext($this->_fancyAdmin->getContext())->byEmail($values['identity']['email'])->fetchOneOrNull())
) {
/** @var Identity $identity */
$identity = new ($this->_em->findEntityClassByInterface(Identity::class));
$identity->setContext($this->_fancyAdmin->getContext());
$this->_em->persist($identity);
}
$entity->setIdentity($identity);
}
public function isAllowedToEdit(): true
{
return true;
}
}