Skip to content

Commit

Permalink
fix(actorfield): default value not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Sep 1, 2022
1 parent 5af827b commit c3baebb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions inc/field/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,23 @@ public function isPrerequisites(): bool {
public function showForm(array $options): void {
$template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig';

$this->question->fields['default_values'] = Html::entities_deep($this->getValueForDesign());
$this->deserializeValue($this->question->fields['default_values']);
// Convert default values to text
$items = json_decode($this->question->fields['default_values'], true);
$this->question->fields['default_values'] = [];
foreach ($items as $item) {
if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) {
$this->question->fields['default_values'][] = $item;
} else if (!empty($item)) {
$user = new User();
$user->getFromDB($item);
if (!$user->isNewItem()) {
// A user known in the DB
$this->question->fields['default_values'][] = $user->fields['name'];
}
}
}
$this->question->fields['default_values'] = implode('\r\n', $this->question->fields['default_values']);

TemplateRenderer::getInstance()->display($template, [
'item' => $this->question,
'params' => $options,
Expand Down Expand Up @@ -309,7 +324,7 @@ public function prepareQuestionInputForSave($input) {
$this->value = $parsed;
$input['default_values'] = '';
if ($this->value !== null && $this->value != '') {
$input['default_value'] = json_encode($this->value);
$input['default_values'] = json_encode($this->value);
}

return $input;
Expand Down
2 changes: 1 addition & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PluginFormcreatorQuestion extends CommonDBChild implements
static public $items_id = 'plugin_formcreator_sections_id';

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

private $skipChecks = false;

Expand Down

0 comments on commit c3baebb

Please sign in to comment.