From e23fbd1cc1b98603ebec5cace6f8bc7730247ea4 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 20 Sep 2023 15:07:16 +0100 Subject: [PATCH] MDL-79256 customfield_textarea: don't autoclean content when editing. --- .../textarea/classes/data_controller.php | 35 ++++++++++++------- .../textarea/classes/field_controller.php | 9 ++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/customfield/field/textarea/classes/data_controller.php b/customfield/field/textarea/classes/data_controller.php index 3d52fe15bc4..1f0caa3d02a 100644 --- a/customfield/field/textarea/classes/data_controller.php +++ b/customfield/field/textarea/classes/data_controller.php @@ -93,17 +93,21 @@ class data_controller extends \core_customfield\data_controller { if (!$this->get('id')) { $this->data->set('value', ''); $this->data->set('valueformat', FORMAT_MOODLE); + $this->data->set('valuetrust', false); $this->save(); } if (array_key_exists('text', $fromform)) { $textoptions = $this->value_editor_options(); + $context = $textoptions['context']; + $data = (object) ['field_editor' => $fromform]; - $data = file_postupdate_standard_editor($data, 'field', $textoptions, $textoptions['context'], + $data = file_postupdate_standard_editor($data, 'field', $textoptions, $context, 'customfield_textarea', 'value', $this->get('id')); + $this->data->set('value', $data->field); $this->data->set('valueformat', $data->fieldformat); - + $this->data->set('valuetrust', trusttext_trusted($context)); $this->save(); } } @@ -118,18 +122,19 @@ class data_controller extends \core_customfield\data_controller { */ public function instance_form_before_set_data(\stdClass $instance) { $textoptions = $this->value_editor_options(); + $context = $textoptions['context']; if ($this->get('id')) { $text = $this->get('value'); $format = $this->get('valueformat'); - $temp = (object)['field' => $text, 'fieldformat' => $format]; - file_prepare_standard_editor($temp, 'field', $textoptions, $textoptions['context'], 'customfield_textarea', + $temp = (object) ['field' => $text, 'fieldformat' => $format, 'fieldtrust' => trusttext_trusted($context)]; + file_prepare_standard_editor($temp, 'field', $textoptions, $context, 'customfield_textarea', 'value', $this->get('id')); $value = $temp->field_editor; } else { $text = $this->get_field()->get_configdata_property('defaultvalue'); $format = $this->get_field()->get_configdata_property('defaultvalueformat'); - $temp = (object)['field' => $text, 'fieldformat' => $format]; - file_prepare_standard_editor($temp, 'field', $textoptions, $textoptions['context'], 'customfield_textarea', + $temp = (object) ['field' => $text, 'fieldformat' => $format, 'fieldtrust' => trusttext_trusted($context)]; + file_prepare_standard_editor($temp, 'field', $textoptions, $context, 'customfield_textarea', 'defaultvalue', $this->get_field()->get('id')); $value = $temp->field_editor; } @@ -194,14 +199,20 @@ class data_controller extends \core_customfield\data_controller { $context = $this->get_context(); $processed = file_rewrite_pluginfile_urls($value, 'pluginfile.php', $context->id, 'customfield_textarea', 'value', $dataid); - $value = format_text($processed, $this->get('valueformat'), ['context' => $context]); + $value = format_text($processed, $this->get('valueformat'), [ + 'context' => $context, + 'trusted' => $this->get('valuetrust'), + ]); } else { - $fieldid = $this->get_field()->get('id'); - $configcontext = $this->get_field()->get_handler()->get_configuration_context(); + $field = $this->get_field(); + + $context = $field->get_handler()->get_configuration_context(); $processed = file_rewrite_pluginfile_urls($value, 'pluginfile.php', - $configcontext->id, 'customfield_textarea', 'defaultvalue', $fieldid); - $valueformat = $this->get_field()->get_configdata_property('defaultvalueformat'); - $value = format_text($processed, $valueformat, ['context' => $configcontext]); + $context->id, 'customfield_textarea', 'defaultvalue', $field->get('id')); + $value = format_text($processed, $field->get_configdata_property('defaultvalueformat'), [ + 'context' => $context, + 'trusted' => true, + ]); } return $value; diff --git a/customfield/field/textarea/classes/field_controller.php b/customfield/field/textarea/classes/field_controller.php index d27f802ceea..d0a84b480c7 100644 --- a/customfield/field/textarea/classes/field_controller.php +++ b/customfield/field/textarea/classes/field_controller.php @@ -110,10 +110,17 @@ class field_controller extends \core_customfield\field_controller { public function value_editor_options(\context $context = null) { global $CFG; require_once($CFG->libdir.'/formslib.php'); + if (!$context) { $context = $this->get_handler()->get_configuration_context(); } - return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context]; + + return [ + 'context' => $context, + 'trusttext' => true, + 'maxfiles' => EDITOR_UNLIMITED_FILES, + 'maxbytes' => $CFG->maxbytes, + ]; } /**