|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bone\User\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Del\Form\Field\FieldInterface; |
|
6
|
|
|
use Del\Form\Field\Hidden; |
|
7
|
|
|
use Del\Form\Field\Select; |
|
8
|
|
|
use Del\Form\Field\Text; |
|
9
|
|
|
use Del\Form\Field\Transformer\DateTimeTransformer; |
|
10
|
|
|
use Del\Form\FormInterface; |
|
11
|
|
|
use Del\Form\Transformer\CountryTransformer; |
|
12
|
|
|
use Del\Repository\CountryRepository; |
|
13
|
|
|
|
|
14
|
|
|
trait PersonFormTrait |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var array $disabledFields */ |
|
17
|
|
|
protected $disabledFields = []; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param FormInterface $form |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function addPersonFormFields(FormInterface $form): void |
|
23
|
|
|
{ |
|
24
|
1 |
|
$firstName = new Text('firstname'); |
|
25
|
1 |
|
$firstName->setLabel('First name'); |
|
26
|
1 |
|
$firstName->setRequired(true); |
|
27
|
|
|
|
|
28
|
1 |
|
$middleName = new Text('middlename'); |
|
29
|
1 |
|
$middleName->setLabel('Middle name'); |
|
30
|
|
|
|
|
31
|
1 |
|
$lastName = new Text('lastname'); |
|
32
|
1 |
|
$lastName->setLabel('Last name'); |
|
33
|
1 |
|
$lastName->setRequired(true); |
|
34
|
|
|
|
|
35
|
1 |
|
$aka = new Text('aka'); |
|
36
|
1 |
|
$aka->setLabel('A.K.A.'); |
|
37
|
|
|
|
|
38
|
1 |
|
$dob = new Text('dob'); |
|
39
|
1 |
|
$dob->setLabel('Date of Birth'); |
|
40
|
1 |
|
$dob->setClass('form-control datepicker'); |
|
41
|
1 |
|
$dob->setTransformer(new DateTimeTransformer('d/m/Y')); |
|
42
|
1 |
|
$dob->setRequired(true); |
|
43
|
|
|
|
|
44
|
1 |
|
$birthPlace = new Text('birthplace'); |
|
45
|
1 |
|
$birthPlace->setLabel('Birth place'); |
|
46
|
|
|
|
|
47
|
1 |
|
$country = new Select('country'); |
|
48
|
1 |
|
$country->setLabel('Country'); |
|
49
|
1 |
|
$country->setTransformer(new CountryTransformer()); |
|
50
|
1 |
|
$countryRepository = new CountryRepository(); |
|
51
|
1 |
|
$countries = $countryRepository->findAllCountries(); |
|
52
|
1 |
|
$country->setRequired(true); |
|
53
|
1 |
|
$country->setOption('', ''); |
|
54
|
1 |
|
foreach ($countries as $c) { |
|
55
|
1 |
|
$country->setOption($c->getIso(), $c->getName()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
$image = new Hidden('image'); |
|
59
|
1 |
|
$image->setId('image'); |
|
60
|
|
|
|
|
61
|
1 |
|
$this->addFieldIfEnabled('firstname', $firstName, $form); |
|
62
|
1 |
|
$this->addFieldIfEnabled('middlename', $middleName, $form); |
|
63
|
1 |
|
$this->addFieldIfEnabled('lastname', $lastName, $form); |
|
64
|
1 |
|
$this->addFieldIfEnabled('aka', $aka, $form); |
|
65
|
1 |
|
$this->addFieldIfEnabled('dob', $dob, $form); |
|
66
|
1 |
|
$this->addFieldIfEnabled('birthplace', $birthPlace, $form); |
|
67
|
1 |
|
$this->addFieldIfEnabled('country', $country, $form); |
|
68
|
1 |
|
$this->addFieldIfEnabled('image', $image, $form); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
private function addFieldIfEnabled(string $name, FieldInterface $field, FormInterface $form) |
|
72
|
|
|
{ |
|
73
|
1 |
|
in_array($name, $this->disabledFields) ? null : $form->addField($field); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|