1 | <?php namespace Kris\LaravelFormBuilder; |
||
8 | class FormHelper |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var View |
||
13 | */ |
||
14 | protected $view; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $config; |
||
20 | |||
21 | /** |
||
22 | * @var FormBuilder |
||
23 | */ |
||
24 | protected $formBuilder; |
||
25 | |||
26 | /** |
||
27 | * All available field types |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected static $availableFieldTypes = [ |
||
32 | 'text' => 'InputType', |
||
33 | 'email' => 'InputType', |
||
34 | 'url' => 'InputType', |
||
35 | 'tel' => 'InputType', |
||
36 | 'search' => 'InputType', |
||
37 | 'password' => 'InputType', |
||
38 | 'hidden' => 'InputType', |
||
39 | 'number' => 'InputType', |
||
40 | 'date' => 'InputType', |
||
41 | 'file' => 'InputType', |
||
42 | 'image' => 'InputType', |
||
43 | 'color' => 'InputType', |
||
44 | 'datetime-local' => 'InputType', |
||
45 | 'month' => 'InputType', |
||
46 | 'range' => 'InputType', |
||
47 | 'time' => 'InputType', |
||
48 | 'week' => 'InputType', |
||
49 | 'select' => 'SelectType', |
||
50 | 'textarea' => 'TextareaType', |
||
51 | 'button' => 'ButtonType', |
||
52 | 'submit' => 'ButtonType', |
||
53 | 'reset' => 'ButtonType', |
||
54 | 'radio' => 'CheckableType', |
||
55 | 'checkbox' => 'CheckableType', |
||
56 | 'choice' => 'ChoiceType', |
||
57 | 'form' => 'ChildFormType', |
||
58 | 'entity' => 'EntityType', |
||
59 | 'collection' => 'CollectionType', |
||
60 | 'repeated' => 'RepeatedType', |
||
61 | 'static' => 'StaticType' |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * Custom types |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | private $customTypes = []; |
||
70 | |||
71 | /** |
||
72 | * @param View $view |
||
73 | * @param array $config |
||
74 | */ |
||
75 | 81 | public function __construct(View $view, array $config = []) |
|
81 | |||
82 | /** |
||
83 | * @param string $key |
||
84 | * @param string $default |
||
85 | * @return mixed |
||
86 | */ |
||
87 | 81 | public function getConfig($key, $default = null) |
|
91 | |||
92 | /** |
||
93 | * @return View |
||
94 | */ |
||
95 | 27 | public function getView() |
|
99 | |||
100 | /** |
||
101 | * Merge options array |
||
102 | * |
||
103 | * @param array $first |
||
104 | * @param array $second |
||
105 | * @return array |
||
106 | */ |
||
107 | 81 | public function mergeOptions(array $first, array $second) |
|
111 | |||
112 | /** |
||
113 | * Get proper class for field type |
||
114 | * |
||
115 | * @param $type |
||
116 | * @return string |
||
117 | */ |
||
118 | 54 | public function getFieldType($type) |
|
144 | |||
145 | /** |
||
146 | * Convert array of attributes to html attributes |
||
147 | * |
||
148 | * @param $options |
||
149 | * @return string |
||
150 | */ |
||
151 | 63 | public function prepareAttributes($options) |
|
168 | |||
169 | /** |
||
170 | * Add custom field |
||
171 | * |
||
172 | * @param $name |
||
173 | * @param $class |
||
174 | */ |
||
175 | 3 | public function addCustomField($name, $class) |
|
183 | |||
184 | /** |
||
185 | * Load custom field types from config file |
||
186 | */ |
||
187 | 81 | private function loadCustomTypes() |
|
197 | |||
198 | 4 | public function convertModelToArray($model) |
|
214 | |||
215 | /** |
||
216 | * Format the label to the proper format |
||
217 | * |
||
218 | * @param $name |
||
219 | * @return string |
||
220 | */ |
||
221 | 63 | public function formatLabel($name) |
|
229 | |||
230 | /** |
||
231 | * @param FormField[] $fields |
||
232 | * @return array |
||
233 | */ |
||
234 | 3 | public function mergeFieldsRules($fields) |
|
251 | |||
252 | /** |
||
253 | * @param string $string |
||
254 | * @return string |
||
255 | */ |
||
256 | 62 | public function transformToDotSyntax($string) |
|
260 | } |
||
261 |