1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Form\Type; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\AbstractType; |
6
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
7
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Borut Balažek <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ProfileType extends AbstractType |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param FormBuilderInterface $builder |
16
|
|
|
* @param $options |
17
|
|
|
*/ |
18
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
19
|
|
|
{ |
20
|
|
|
$builder->add('title', 'text', array( |
21
|
|
|
'label' => 'Title', |
22
|
|
|
'required' => false, |
23
|
|
|
)); |
24
|
|
|
|
25
|
|
|
$builder->add('firstName', 'text', array( |
26
|
|
|
'label' => 'First name', |
27
|
|
|
)); |
28
|
|
|
|
29
|
|
|
$builder->add('middleName', 'text', array( |
30
|
|
|
'label' => 'Middle name', |
31
|
|
|
'required' => false, |
32
|
|
|
)); |
33
|
|
|
|
34
|
|
|
$builder->add('lastName', 'text', array( |
35
|
|
|
'label' => 'Last name', |
36
|
|
|
'required' => false, |
37
|
|
|
)); |
38
|
|
|
|
39
|
|
|
$builder->add( |
40
|
|
|
'gender', |
41
|
|
|
new GenderType(), |
42
|
|
|
array( |
43
|
|
|
'label' => 'Gender', |
44
|
|
|
'required' => false, |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$builder->add('birthdate', 'birthday', array( |
49
|
|
|
'label' => 'Birthdate', |
50
|
|
|
'required' => false, |
51
|
|
|
)); |
52
|
|
|
|
53
|
|
|
$builder->add('image', 'file', array( |
54
|
|
|
'required' => false, |
55
|
|
|
)); |
56
|
|
|
$builder->add('removeImage', 'checkbox', array( |
57
|
|
|
'required' => false, |
58
|
|
|
'data' => false, |
59
|
|
|
'label' => 'Remove image?', |
60
|
|
|
'attr' => array( |
61
|
|
|
'data-help-text' => 'Should the image be removed (goes into effect after the save)?', |
62
|
|
|
), |
63
|
|
|
)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param OptionsResolverInterface $resolver |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function setDefaultOptions(OptionsResolverInterface $resolver) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$resolver->setDefaults(array( |
72
|
|
|
'data_class' => 'Application\Entity\ProfileEntity', |
73
|
|
|
'validation_groups' => array('newAndEdit'), |
74
|
|
|
'csrf_protection' => true, |
75
|
|
|
'csrf_field_name' => 'csrf_token', |
76
|
|
|
)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getName() |
83
|
|
|
{ |
84
|
|
|
return 'profile'; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.