|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Form; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\User; |
|
6
|
|
|
use Symfony\Component\Form\AbstractType; |
|
7
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
|
8
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
9
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
10
|
|
|
use Symfony\Component\Form\FormEvent; |
|
11
|
|
|
use Symfony\Component\Form\FormEvents; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class SurveyType. |
|
15
|
|
|
|
|
16
|
|
|
*/ |
|
17
|
|
|
class SurveyType extends AbstractType |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
21
|
|
|
* |
|
22
|
|
|
* @param FormBuilderInterface $builder |
|
23
|
|
|
* @param array $options |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
26
|
|
|
{ |
|
27
|
|
|
$builder |
|
28
|
2 |
|
->add('user', EntityType::class, array( |
|
29
|
2 |
|
'class' => 'AppBundle:User', |
|
30
|
2 |
|
'label' => 'Choose intern', |
|
31
|
|
|
'choice_label' => function ($user) { |
|
32
|
|
|
/** @var User $user */ |
|
33
|
1 |
|
$userName = $user->getFirstName().' '.$user->getLastName(); |
|
34
|
1 |
|
return $userName; |
|
35
|
2 |
|
}, |
|
36
|
|
|
)) |
|
37
|
|
|
; |
|
38
|
2 |
|
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
39
|
2 |
|
$survey = $event->getData(); |
|
40
|
2 |
|
$form = $event->getForm(); |
|
41
|
2 |
|
if ($survey->getUser() !== null) { |
|
42
|
1 |
|
$form->remove('user'); |
|
43
|
|
|
} |
|
44
|
2 |
|
}); |
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
public function configureOptions(OptionsResolver $resolver) |
|
48
|
|
|
{ |
|
49
|
2 |
|
$resolver->setDefaults(array( |
|
50
|
2 |
|
'data_class' => 'AppBundle\Entity\Survey\Survey', |
|
51
|
|
|
)); |
|
52
|
2 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|