1 | <?php |
||
41 | class FieldBuilder extends ParentDelegationBuilder implements NamedBuilder |
||
42 | { |
||
43 | /** |
||
44 | * Field Type |
||
45 | * @var string |
||
46 | */ |
||
47 | private $type; |
||
48 | |||
49 | /** |
||
50 | * Additional Field Configuration |
||
51 | * @var array |
||
52 | */ |
||
53 | private $config; |
||
54 | |||
55 | /** |
||
56 | * @param string $name Field Name, conventionally 'snake_case'. |
||
57 | * @param string $type Field Type. |
||
58 | * @param array $config Additional Field Configuration. |
||
59 | */ |
||
60 | public function __construct($name, $type, $config = []) |
||
71 | |||
72 | /** |
||
73 | * @return array |
||
74 | */ |
||
75 | private function getConfig() |
||
79 | |||
80 | /** |
||
81 | * Set a config key -> value pair |
||
82 | * @param string $key |
||
83 | * @param mixed $value |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setConfig($key, $value) |
||
90 | |||
91 | /** |
||
92 | * Update multiple config values using and array of key -> value pairs. |
||
93 | * @param array $config |
||
94 | * @return $this |
||
95 | */ |
||
96 | public function updateConfig($config) |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getName() |
||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getKey() |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getLabel() |
||
125 | |||
126 | /** |
||
127 | * Will prepend `field_` if missing. |
||
128 | * @param string $key |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function setKey($key) |
||
139 | |||
140 | public function setCustomKey($key) |
||
146 | |||
147 | /** |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function hasCustomKey() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Will set field required. |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setRequired() |
||
164 | |||
165 | /** |
||
166 | * Will set field unrequired. |
||
167 | * @return $this |
||
168 | */ |
||
169 | public function setUnrequired() |
||
173 | |||
174 | /** |
||
175 | * Will set field's instructions. |
||
176 | * @param string $instructions |
||
177 | * @return $this |
||
178 | */ |
||
179 | public function setInstructions($instructions) |
||
183 | |||
184 | /** |
||
185 | * Will set field's defaultValue. |
||
186 | * @param string $defaultValue |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function setDefaultValue($defaultValue) |
||
193 | |||
194 | /** |
||
195 | * Add a conditional logic statement that will determine if the last added |
||
196 | * field will display or not. You can add `or` or `and` calls after |
||
197 | * to build complex logic. Any other function call will return you to the |
||
198 | * parentContext. |
||
199 | * @param string $name Dependent field name |
||
200 | * (choice type: radio, checkbox, select, trueFalse) |
||
201 | * @param string $operator ==, != |
||
202 | * @param string $value 1 or choice value |
||
203 | * @return ConditionalBuilder |
||
204 | */ |
||
205 | public function conditional($name, $operator, $value) |
||
214 | |||
215 | /** |
||
216 | * Build the field configuration array |
||
217 | * @return array Field configuration array |
||
218 | */ |
||
219 | public function build() |
||
233 | |||
234 | /** |
||
235 | * Create a field label based on the field's name. Generates title case. |
||
236 | * @param string $name |
||
237 | * @return string label |
||
238 | */ |
||
239 | protected function generateLabel($name) |
||
243 | |||
244 | /** |
||
245 | * Generates a snaked cased name. |
||
246 | * @param string $name |
||
247 | * @return string |
||
248 | */ |
||
249 | protected function generateName($name) |
||
253 | } |
||
254 |