1 | <?php namespace Kris\LaravelFormBuilder; |
||
9 | class FormHelper |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var View |
||
14 | */ |
||
15 | protected $view; |
||
16 | |||
17 | /** |
||
18 | * @var Translator |
||
19 | */ |
||
20 | protected $translator; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | /** |
||
28 | * @var FormBuilder |
||
29 | */ |
||
30 | protected $formBuilder; |
||
31 | |||
32 | /** |
||
33 | * All available field types |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected static $availableFieldTypes = [ |
||
38 | 'text' => 'InputType', |
||
39 | 'email' => 'InputType', |
||
40 | 'url' => 'InputType', |
||
41 | 'tel' => 'InputType', |
||
42 | 'search' => 'InputType', |
||
43 | 'password' => 'InputType', |
||
44 | 'hidden' => 'InputType', |
||
45 | 'number' => 'InputType', |
||
46 | 'date' => 'InputType', |
||
47 | 'file' => 'InputType', |
||
48 | 'image' => 'InputType', |
||
49 | 'color' => 'InputType', |
||
50 | 'datetime-local' => 'InputType', |
||
51 | 'month' => 'InputType', |
||
52 | 'range' => 'InputType', |
||
53 | 'time' => 'InputType', |
||
54 | 'week' => 'InputType', |
||
55 | 'select' => 'SelectType', |
||
56 | 'textarea' => 'TextareaType', |
||
57 | 'button' => 'ButtonType', |
||
58 | 'submit' => 'ButtonType', |
||
59 | 'reset' => 'ButtonType', |
||
60 | 'radio' => 'CheckableType', |
||
61 | 'checkbox' => 'CheckableType', |
||
62 | 'choice' => 'ChoiceType', |
||
63 | 'form' => 'ChildFormType', |
||
64 | 'entity' => 'EntityType', |
||
65 | 'collection' => 'CollectionType', |
||
66 | 'repeated' => 'RepeatedType', |
||
67 | 'static' => 'StaticType' |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * Custom types |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | private $customTypes = []; |
||
76 | |||
77 | /** |
||
78 | * @param View $view |
||
79 | * @param array $config |
||
80 | */ |
||
81 | 82 | public function __construct(View $view, array $config = [], Translator $translator) |
|
88 | |||
89 | /** |
||
90 | * @param string $key |
||
91 | * @param string $default |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 82 | public function getConfig($key, $default = null) |
|
98 | |||
99 | /** |
||
100 | * @return View |
||
101 | */ |
||
102 | 27 | public function getView() |
|
106 | |||
107 | /** |
||
108 | * Merge options array |
||
109 | * |
||
110 | * @param array $first |
||
111 | * @param array $second |
||
112 | * @return array |
||
113 | */ |
||
114 | 82 | public function mergeOptions(array $first, array $second) |
|
118 | |||
119 | /** |
||
120 | * Get proper class for field type |
||
121 | * |
||
122 | * @param $type |
||
123 | * @return string |
||
124 | */ |
||
125 | 54 | public function getFieldType($type) |
|
151 | |||
152 | /** |
||
153 | * Convert array of attributes to html attributes |
||
154 | * |
||
155 | * @param $options |
||
156 | * @return string |
||
157 | */ |
||
158 | 63 | public function prepareAttributes($options) |
|
175 | |||
176 | /** |
||
177 | * Add custom field |
||
178 | * |
||
179 | * @param $name |
||
180 | * @param $class |
||
181 | */ |
||
182 | 3 | public function addCustomField($name, $class) |
|
190 | |||
191 | /** |
||
192 | * Load custom field types from config file |
||
193 | */ |
||
194 | 82 | private function loadCustomTypes() |
|
204 | |||
205 | 5 | public function convertModelToArray($model) |
|
221 | |||
222 | /** |
||
223 | * Format the label to the proper format |
||
224 | * |
||
225 | * @param $name |
||
226 | * @return string |
||
227 | */ |
||
228 | 63 | public function formatLabel($name) |
|
240 | |||
241 | /** |
||
242 | * @param FormField[] $fields |
||
243 | * @return array |
||
244 | */ |
||
245 | 3 | public function mergeFieldsRules($fields) |
|
262 | |||
263 | /** |
||
264 | * @param string $string |
||
265 | * @return string |
||
266 | */ |
||
267 | 62 | public function transformToDotSyntax($string) |
|
271 | } |
||
272 |