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