Skip to content

Commit f1606af

Browse files
committed
fix(actors): fix edit of an existing question of type actors
Signed-off-by: btry <tbugier@teclib.com>
1 parent d94fcbc commit f1606af

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

inc/field.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,23 @@ public function prepareQuestionInputForSave($input) {
6565

6666
/**
6767
* Prepares an answer value for output in a target object
68-
* @param string|array $input the answer to format for a target (ticket or change)
68+
* @param string|array $input the answer to format for a target (ticket or change)
6969
* @return string
7070
*/
7171
public function prepareQuestionInputForTarget($input) {
7272
return Toolbox::addslashes_deep($input);
7373
}
7474

75+
/**
76+
* Prepares a default value or set of values for question edition
77+
*
78+
* @param string $input
79+
* @return string
80+
*/
81+
public function prepareQuestionValuesForEdit($input) {
82+
return $input;
83+
}
84+
7585
/**
7686
* Output HTML to display the field
7787
* @param boolean $canEdit is the field editable ?

inc/fieldinterface.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ public static function getPrefs();
4141
public static function getJSFields();
4242
public function prepareQuestionInputForSave($input);
4343
public function prepareQuestionInputForTarget($input);
44+
public function prepareQuestionValuesForEdit($input);
4445
}

inc/fields/actorfield.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,8 @@ public static function getJSFields() {
269269
$prefs = self::getPrefs();
270270
return "tab_fields_fields['actor'] = 'showFields(" . implode(', ', $prefs) . ");';";
271271
}
272+
273+
public function prepareQuestionValuesForEdit($input) {
274+
return $this->deserializeValue($input);
275+
}
272276
}

inc/question.class.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,15 @@ public function showForm($ID, $options = []) {
827827
echo '</label>';
828828
echo '</td>';
829829
echo '<td>';
830+
$defaultValues = "";
831+
if (!$this->isNewItem()) {
832+
$fieldObject = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this);
833+
$defaultValues = $fieldObject->prepareQuestionValuesForEdit($this->fields['default_values']);
834+
}
830835
echo '<textarea name="default_values" id="default_values" rows="4" cols="40"'
831-
.'style="width: 90%">'.$this->fields['default_values'].'</textarea>';
836+
.'style="width: 90%">'
837+
.$defaultValues
838+
.'</textarea>';
832839
echo '<div id="dropdown_default_value_field">';
833840
if (!empty($this->fields['values'])) {
834841
if ($this->fields['fieldtype'] == 'glpiselect' && class_exists($this->fields['values'])) {

0 commit comments

Comments
 (0)