Skip to content

Commit

Permalink
fix(actors): fix edit of an existing question of type actors
Browse files Browse the repository at this point in the history
Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 7, 2018
1 parent d94fcbc commit f1606af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion inc/field.class.php
Expand Up @@ -65,13 +65,23 @@ public function prepareQuestionInputForSave($input) {

/**
* Prepares an answer value for output in a target object
* @param string|array $input the answer to format for a target (ticket or change)
* @param string|array $input the answer to format for a target (ticket or change)
* @return string
*/
public function prepareQuestionInputForTarget($input) {
return Toolbox::addslashes_deep($input);
}

/**
* Prepares a default value or set of values for question edition
*
* @param string $input
* @return string
*/
public function prepareQuestionValuesForEdit($input) {
return $input;
}

/**
* Output HTML to display the field
* @param boolean $canEdit is the field editable ?
Expand Down
1 change: 1 addition & 0 deletions inc/fieldinterface.class.php
Expand Up @@ -41,4 +41,5 @@ public static function getPrefs();
public static function getJSFields();
public function prepareQuestionInputForSave($input);
public function prepareQuestionInputForTarget($input);
public function prepareQuestionValuesForEdit($input);
}
4 changes: 4 additions & 0 deletions inc/fields/actorfield.class.php
Expand Up @@ -269,4 +269,8 @@ public static function getJSFields() {
$prefs = self::getPrefs();
return "tab_fields_fields['actor'] = 'showFields(" . implode(', ', $prefs) . ");';";
}

public function prepareQuestionValuesForEdit($input) {
return $this->deserializeValue($input);
}
}
9 changes: 8 additions & 1 deletion inc/question.class.php
Expand Up @@ -827,8 +827,15 @@ public function showForm($ID, $options = []) {
echo '</label>';
echo '</td>';
echo '<td>';
$defaultValues = "";
if (!$this->isNewItem()) {
$fieldObject = PluginFormcreatorFields::getFieldInstance($this->getField('fieldtype'), $this);
$defaultValues = $fieldObject->prepareQuestionValuesForEdit($this->fields['default_values']);
}
echo '<textarea name="default_values" id="default_values" rows="4" cols="40"'
.'style="width: 90%">'.$this->fields['default_values'].'</textarea>';
.'style="width: 90%">'
.$defaultValues
.'</textarea>';
echo '<div id="dropdown_default_value_field">';
if (!empty($this->fields['values'])) {
if ($this->fields['fieldtype'] == 'glpiselect' && class_exists($this->fields['values'])) {
Expand Down

0 comments on commit f1606af

Please sign in to comment.