1 | <?php |
||
7 | class FieldGroup |
||
8 | { |
||
9 | /** |
||
10 | * The form that holds all the added fields. |
||
11 | * |
||
12 | * @var Form |
||
13 | */ |
||
14 | protected $form; |
||
15 | |||
16 | /** |
||
17 | * The parent form. |
||
18 | * |
||
19 | * @var Form |
||
20 | */ |
||
21 | protected $parent; |
||
22 | |||
23 | /** |
||
24 | * @var FormHelper |
||
25 | */ |
||
26 | protected $formHelper; |
||
27 | |||
28 | /** |
||
29 | * All options for the group. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $options = []; |
||
34 | |||
35 | /** |
||
36 | * The template name to be used. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $template; |
||
41 | |||
42 | /** |
||
43 | * FieldGroup constructor. |
||
44 | * @param Form $parent |
||
45 | * @param array $options |
||
46 | */ |
||
47 | 1 | public function __construct(Form $parent, array $options = []) |
|
55 | |||
56 | /** |
||
57 | * Get the template, can be config variable or view path. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 1 | protected function getTemplate() |
|
65 | |||
66 | /** |
||
67 | * Default options for field. |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 1 | protected function getDefaults() |
|
79 | |||
80 | /** |
||
81 | * @return Fields\FormField[] |
||
82 | */ |
||
83 | 1 | public function getFields() |
|
87 | |||
88 | 1 | public function hasField(string $fieldName) |
|
92 | |||
93 | /** |
||
94 | * @param $name |
||
95 | * @param string $type |
||
96 | * @param array $options |
||
97 | * @return $this |
||
98 | */ |
||
99 | 1 | public function add($name, $type = 'text', array $options = []) |
|
105 | |||
106 | /** |
||
107 | * @param \Closure $callback |
||
108 | * @param FieldGroup|null $fieldGroup |
||
109 | * @return $this |
||
110 | */ |
||
111 | 1 | public function group(\Closure $callback, FieldGroup $fieldGroup = null) |
|
117 | |||
118 | /** |
||
119 | * Render the field. |
||
120 | * |
||
121 | * @param array $options |
||
122 | * @return string |
||
123 | */ |
||
124 | 1 | public function render(array $options = []) |
|
137 | |||
138 | /** |
||
139 | * Return the extra render data for this form field, passed into the field's template directly. |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | 1 | protected function getRenderData() |
|
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | 1 | protected function getViewTemplate() |
|
155 | |||
156 | /** |
||
157 | * Get single option from options array. Can be used with dot notation ('attr.class'). |
||
158 | * |
||
159 | * @param string $option |
||
160 | * @param mixed|null $default |
||
161 | * @return mixed |
||
162 | */ |
||
163 | 1 | public function getOption($option, $default = null) |
|
167 | |||
168 | /** |
||
169 | * @return Form |
||
170 | */ |
||
171 | public function getParent() |
||
175 | |||
176 | /** |
||
177 | * @return Form |
||
178 | */ |
||
179 | 1 | public function getForm() |
|
183 | |||
184 | /** |
||
185 | * @param Form|FieldGroup $fieldsContainer |
||
186 | * @return array (Fields\FormField|FieldGroup)[] |
||
187 | */ |
||
188 | 8 | public static function buildFieldsForRendering($fieldsContainer) |
|
227 | |||
228 | } |