Skip to content

Commit

Permalink
fix(textareafield): inline imagein default value converted to document
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Dec 1, 2020
1 parent 7c48d03 commit 14e5f4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
37 changes: 35 additions & 2 deletions inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ public function getDesignSpecializationField() {
'name' => 'default_values',
'id' => 'default_values',
'value' => $this->getValueForDesign(),
'enable_rich_text' => true,
'enable_richtext' => true,
'filecontainer' => 'default_values_info',
'display' => false,
]);
$additions .= Html::initEditorSystem('default_values', '', false);
//$additions .= Html::initEditorSystem('default_values', '', false);
$additions .= '</td>';
$additions .= '</tr>';

Expand Down Expand Up @@ -116,6 +117,16 @@ public function serializeValue() {
return '';
}

$key = 'formcreator_field_' . $this->question->getID();
$this->value = $this->question->addFiles(
[$key => $this->value] + $this->uploads,
[
'force_update' => true,
'content_field' => $key,
'name' => $key,
]
)[$key];

return Toolbox::addslashes_deep($this->value);
}

Expand Down Expand Up @@ -149,7 +160,29 @@ public function isValid() {
}

public function prepareQuestionInputForSave($input) {
$success = true;
$fieldType = $this->getFieldTypeName();
if (isset($input['_parameters'][$fieldType]['regex']['regex']) && !empty($input['_parameters'][$fieldType]['regex']['regex'])) {
$regex = Toolbox::stripslashes_deep($input['_parameters'][$fieldType]['regex']['regex']);
$success = $this->checkRegex($regex);
if (!$success) {
Session::addMessageAfterRedirect(__('The regular expression is invalid', 'formcreator'), false, ERROR);
}
}
if (!$success) {
return [];
}
$this->value = Toolbox::stripslashes_deep(str_replace('\r\n', "\r\n", $input['default_values']));

// Handle uploads
$key = 'formcreator_field_' . $this->question->getID();
if (isset($input['_tag_default_values']) && isset($input['_default_values']) && isset($input['_prefix_default_values'])) {
$this->uploads['_' . $key] = $input['_default_values'];
$this->uploads['_prefix_' . $key] = $input['_prefix_default_values'];
$this->uploads['_tag_' . $key] = $input['_tag_default_values'];
}
$input[$key] = $input['default_values'];

return $input;
}

Expand Down
1 change: 0 additions & 1 deletion inc/field/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ public static function getName() {
public function prepareQuestionInputForSave($input) {
$success = true;
$fieldType = $this->getFieldTypeName();
// Add leading and trailing regex marker automaticaly
if (isset($input['_parameters'][$fieldType]['regex']['regex']) && !empty($input['_parameters'][$fieldType]['regex']['regex'])) {
$regex = Toolbox::stripslashes_deep($input['_parameters'][$fieldType]['regex']['regex']);
$success = $this->checkRegex($regex);
Expand Down
1 change: 1 addition & 0 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ public function showForm($ID, $options = []) {
'id' => 'description',
'value' => $this->fields['description'],
'enable_richtext' => true,
'filecontainer' => 'description_info',
'display' => false,
]);
echo '</td>';
Expand Down

0 comments on commit 14e5f4b

Please sign in to comment.