Skip to content

Commit c3baebb

Browse files
committed
fix(actorfield): default value not saved
1 parent 5af827b commit c3baebb

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

inc/field/actorfield.class.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,23 @@ public function isPrerequisites(): bool {
5454
public function showForm(array $options): void {
5555
$template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig';
5656

57-
$this->question->fields['default_values'] = Html::entities_deep($this->getValueForDesign());
58-
$this->deserializeValue($this->question->fields['default_values']);
57+
// Convert default values to text
58+
$items = json_decode($this->question->fields['default_values'], true);
59+
$this->question->fields['default_values'] = [];
60+
foreach ($items as $item) {
61+
if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) {
62+
$this->question->fields['default_values'][] = $item;
63+
} else if (!empty($item)) {
64+
$user = new User();
65+
$user->getFromDB($item);
66+
if (!$user->isNewItem()) {
67+
// A user known in the DB
68+
$this->question->fields['default_values'][] = $user->fields['name'];
69+
}
70+
}
71+
}
72+
$this->question->fields['default_values'] = implode('\r\n', $this->question->fields['default_values']);
73+
5974
TemplateRenderer::getInstance()->display($template, [
6075
'item' => $this->question,
6176
'params' => $options,
@@ -309,7 +324,7 @@ public function prepareQuestionInputForSave($input) {
309324
$this->value = $parsed;
310325
$input['default_values'] = '';
311326
if ($this->value !== null && $this->value != '') {
312-
$input['default_value'] = json_encode($this->value);
327+
$input['default_values'] = json_encode($this->value);
313328
}
314329

315330
return $input;

inc/question.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PluginFormcreatorQuestion extends CommonDBChild implements
5252
static public $items_id = 'plugin_formcreator_sections_id';
5353

5454
/** @var PluginFormcreatorFieldInterface|null $field a field describing the question denpending on its field type */
55-
private $field = null;
55+
private ?PluginFormcreatorFieldInterface $field = null;
5656

5757
private $skipChecks = false;
5858

0 commit comments

Comments
 (0)