1 | <?php |
||
8 | class FieldBuilder extends ParentDelegationBuilder implements NamedBuilder |
||
9 | { |
||
10 | /** |
||
11 | * Field Type |
||
12 | * @var string |
||
13 | */ |
||
14 | private $type; |
||
15 | |||
16 | /** |
||
17 | * Additional Field Configuration |
||
18 | * @var array |
||
19 | */ |
||
20 | private $config; |
||
21 | |||
22 | /** |
||
23 | * @param string $name Field Name, conventionally 'snake_case'. |
||
24 | * @param string $type Field Type. |
||
25 | * @param array $config Additional Field Configuration. |
||
26 | */ |
||
27 | public function __construct($name, $type, $config = []) |
||
38 | |||
39 | /** |
||
40 | * @return array |
||
41 | */ |
||
42 | private function getConfig() |
||
46 | |||
47 | /** |
||
48 | * Set a config key -> value pair |
||
49 | * @param string $key |
||
50 | * @param mixed $value |
||
51 | * @return $this |
||
52 | */ |
||
53 | public function setConfig($key, $value) |
||
57 | |||
58 | /** |
||
59 | * Update multiple config values using and array of key -> value pairs. |
||
60 | * @param array $config |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function updateConfig($config) |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getName() |
||
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getKey() |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getLabel() |
||
92 | |||
93 | /** |
||
94 | * Will prepend `field_` if missing. |
||
95 | * @param string $key |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setKey($key) |
||
106 | |||
107 | /** |
||
108 | * Will set field required. |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function setRequired() |
||
115 | |||
116 | /** |
||
117 | * Will set field unrequired. |
||
118 | * @return $this |
||
119 | */ |
||
120 | public function setUnrequired() |
||
124 | |||
125 | /** |
||
126 | * Will set field's instructions. |
||
127 | * @param string $instructions |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function setInstructions($instructions) |
||
134 | |||
135 | /** |
||
136 | * Will set field's defaultValue. |
||
137 | * @param string $defaultValue |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function setDefaultValue($defaultValue) |
||
144 | |||
145 | /** |
||
146 | * Add a conditional logic statement that will determine if the last added |
||
147 | * field will display or not. You can add `or` or `and` calls after |
||
148 | * to build complex logic. Any other function call will return you to the |
||
149 | * parentContext. |
||
150 | * @param string $name Dependent field name |
||
151 | * (choice type: radio, checkbox, select, trueFalse) |
||
152 | * @param string $operator ==, != |
||
153 | * @param string $value 1 or choice value |
||
154 | * @return ConditionalBuilder |
||
155 | */ |
||
156 | public function conditional($name, $operator, $value) |
||
165 | |||
166 | /** |
||
167 | * Build the field configuration array |
||
168 | * @return array Field configuration array |
||
169 | */ |
||
170 | public function build() |
||
184 | |||
185 | /** |
||
186 | * Create a field label based on the field's name. Generates title case. |
||
187 | * @param string $name |
||
188 | * @return string label |
||
189 | */ |
||
190 | protected function generateLabel($name) |
||
194 | |||
195 | /** |
||
196 | * Generates a snaked cased name. |
||
197 | * @param string $name |
||
198 | * @return string |
||
199 | */ |
||
200 | protected function generateName($name) |
||
204 | } |
||
205 |