1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Black\Common\Application\Form\Type; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\AbstractType; |
6
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
7
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
8
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
9
|
|
|
use Black\Common\Application\Form\Transformer\ValuetoModelsOrNullTransformer; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CustomChoiceListType |
13
|
|
|
* |
14
|
|
|
* CustomChoiceListType create a Choice list |
15
|
|
|
*/ |
16
|
|
|
class CustomChoiceListType extends AbstractType |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var |
20
|
|
|
*/ |
21
|
|
|
protected $choiceList; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var |
25
|
|
|
*/ |
26
|
|
|
protected $choiceListName; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var |
30
|
|
|
*/ |
31
|
|
|
protected $manager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Construct the ChoiceList |
35
|
|
|
* |
36
|
|
|
* @param string $choiceList |
37
|
|
|
* @param string $choiceListName |
38
|
|
|
*/ |
39
|
|
|
public function __construct($choiceList, $choiceListName) |
40
|
|
|
{ |
41
|
|
|
$this->choiceList = $choiceList; |
42
|
|
|
$this->choiceListName = $choiceListName; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
49
|
|
|
{ |
50
|
|
|
if ($this->manager !== null) { |
51
|
|
|
$builder->addModelTransformer( |
52
|
|
|
new ValuetoModelsOrNullTransformer($this->manager) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getParent() |
61
|
|
|
{ |
62
|
|
|
return ChoiceType::class; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function configureOptions(OptionsResolver $resolver) |
69
|
|
|
{ |
70
|
|
|
$resolver->setDefaults(['choice_list' => $this->choiceList]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set the manager for the Choice List |
75
|
|
|
* |
76
|
|
|
* @param string $manager |
77
|
|
|
*/ |
78
|
|
|
public function setManager($manager) |
79
|
|
|
{ |
80
|
|
|
$this->manager = $manager; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|