1 | <?php |
||
5 | class ChoiceType extends ParentType |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | protected $choiceType = 'select'; |
||
11 | |||
12 | /** |
||
13 | * @inheritdoc |
||
14 | */ |
||
15 | protected $valueProperty = 'selected'; |
||
16 | |||
17 | /** |
||
18 | * @inheritdoc |
||
19 | */ |
||
20 | 15 | protected function getTemplate() |
|
24 | |||
25 | /** |
||
26 | * Determine which choice type to use. |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | 15 | protected function determineChoiceField() |
|
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | 15 | protected function getDefaults() |
|
64 | |||
65 | /** |
||
66 | * Create children depending on choice type. |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | 14 | protected function createChildren() |
|
91 | |||
92 | /** |
||
93 | * Build checkable children fields from choice type. |
||
94 | * |
||
95 | * @param string $fieldType |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | 5 | protected function buildCheckableChildren($fieldType) |
|
100 | { |
||
101 | 5 | $multiple = $this->getOption('multiple') ? '[]' : ''; |
|
102 | |||
103 | 5 | foreach ((array)$this->options['choices'] as $key => $choice) { |
|
104 | 4 | $id = str_replace('.', '_', $this->getNameKey()) . '_' . $key; |
|
105 | 4 | $options = $this->formHelper->mergeOptions( |
|
106 | 4 | $this->getOption('choice_options'), |
|
107 | [ |
||
108 | 4 | 'attr' => ['id' => $id], |
|
109 | 4 | 'label_attr' => ['for' => $id], |
|
110 | 4 | 'label' => $choice, |
|
111 | 4 | 'checked' => in_array($key, (array)$this->options[$this->valueProperty]), |
|
112 | 4 | 'value' => $key |
|
113 | ] |
||
114 | ); |
||
115 | 4 | $this->children[] = new $fieldType( |
|
116 | 4 | $this->name . $multiple, |
|
117 | 4 | $this->choiceType, |
|
118 | 4 | $this->parent, |
|
119 | $options |
||
120 | ); |
||
121 | } |
||
122 | 5 | } |
|
123 | |||
124 | /** |
||
125 | * Build select field from choice. |
||
126 | * |
||
127 | * @param string $fieldType |
||
128 | */ |
||
129 | 9 | protected function buildSelect($fieldType) |
|
138 | |||
139 | /** |
||
140 | * Creates default wrapper classes for the form element. |
||
141 | * |
||
142 | * @param array $options |
||
143 | * @return array |
||
144 | */ |
||
145 | 15 | protected function setDefaultClasses(array $options = []) |
|
171 | } |
||
172 |