Skip to content

Commit a2b5819

Browse files
stonebuzzbtry
authored andcommitted
feat(fields): manage new fields type plugin
1 parent 5a46297 commit a2b5819

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

inc/field/fieldsfield.class.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function prepareHtmlField($fieldName, $canedit = true, $value = '') {
200200
}
201201

202202
$rand = mt_rand();
203+
$dropdown_type = $this->getField()->fields['type'];
203204

204205
//compute default values
205206
if (!empty($value)) {
@@ -217,11 +218,20 @@ public function prepareHtmlField($fieldName, $canedit = true, $value = '') {
217218
$field['value'] = $value;
218219
}
219220

221+
$dropdown_matches = [];
222+
if (
223+
preg_match('/^dropdown-(?<class>.+)$/i', $dropdown_type, $dropdown_matches)
224+
&& class_exists($dropdown_matches['class'])
225+
) {
226+
$dropdown_type = 'dropdown_extend';
227+
$dropdown_class = $dropdown_matches['class'];
228+
}
229+
220230
$html = "";
221231
$readonly = ($this->getField()->fields['is_readonly'] || !$canedit);
222232
$this->question->fields['required'] = $this->getField()->fields['mandatory'];
223233

224-
switch ($this->getField()->fields['type']) {
234+
switch ($dropdown_type) {
225235
case 'number':
226236
case 'text':
227237
$value = Html::cleanInputText($value);
@@ -356,9 +366,26 @@ public function prepareHtmlField($fieldName, $canedit = true, $value = '') {
356366
$os->getFromDB($value);
357367
$html.= $os->fields['name'];
358368
}
369+
case 'dropdown_extend':
370+
$itemtype = $dropdown_class;
371+
372+
if ($canedit && !$readonly) {
373+
$html.= $itemtype::dropdown(['name' => $fieldName,
374+
'value' => $value,
375+
'entity' => -1,
376+
'right' => 'all',
377+
'display' => false]);
378+
$html .= Html::scriptBlock("$(function() {
379+
pluginFormcreatorInitializeDropdown('$fieldName', '$rand');
380+
});");
381+
} else {
382+
$dropdown_field = new $itemtype();
383+
$dropdown_field->getFromDB($value);
384+
$html.= $dropdown_field->fields['name'];
385+
}
359386
break;
360387
default:
361-
$html .= __('Field type not implemented yet !', 'formcreator');
388+
$html .= sprintf(__('Field \'%1$s\' type not implemented yet !', 'formcreator'), $dropdown_type);
362389
}
363390

364391
unset($_SESSION['plugin']['fields']['values_sent']);

0 commit comments

Comments
 (0)