From 988592c556093afb0c1d330adbde9202a4176814 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 1 Sep 2015 12:23:00 +0800 Subject: [PATCH] MDL-51179 Atto: Extend autosave fix to cover text changes Added new functions to editor api - set/get_text so the original form text can be determined from an editor. When calling use_editor() you should first call set_text() with the text that will be inserted in the form element. There is also a new scheduled task for cleaning Atto autosave drafts. --- lib/adminlib.php | 1 + lib/deprecatedlib.php | 3 +- .../classes/task/autosave_cleanup_task.php | 58 +++++++++++++++++++ lib/editor/atto/db/tasks.php | 44 ++++++++++++++ lib/editor/atto/lang/en/editor_atto.php | 1 + lib/editor/atto/lib.php | 4 +- lib/editor/atto/tests/behat/autosave.feature | 21 +++++++ lib/editor/atto/version.php | 2 +- lib/editorlib.php | 22 +++++++ lib/form/editor.php | 1 + lib/upgrade.txt | 1 + mod/data/field/textarea/field.class.php | 1 + mod/data/templates.php | 4 ++ question/behaviour/rendererbase.php | 1 + question/type/essay/renderer.php | 1 + 15 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 lib/editor/atto/classes/task/autosave_cleanup_task.php create mode 100644 lib/editor/atto/db/tasks.php diff --git a/lib/adminlib.php b/lib/adminlib.php index e9360f0d0da..3563fde4fbc 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2319,6 +2319,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext { } $editor = editors_get_preferred_editor(FORMAT_HTML); + $editor->set_text($data); $editor->use_editor($this->get_id(), array('noclean'=>true)); return format_admin_setting($this, $this->visiblename, diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 8c85c9d60bc..adef5fd4798 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -1003,6 +1003,7 @@ function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='' editors_head_setup(); $editor = editors_get_preferred_editor(FORMAT_HTML); + $editor->set_text($value); $editor->use_editor($id, array('legacy'=>true)); $str .= "\n".''; diff --git a/mod/data/templates.php b/mod/data/templates.php index f2c0388d2f9..32fd7a93f9d 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -218,6 +218,7 @@ if ($mode == 'listtemplate'){ echo '
'; $field = 'listtemplateheader'; + $editor->set_text($data->listtemplateheader); $editor->use_editor($field, $options); echo '
'; @@ -315,6 +316,7 @@ if ($mode == 'listtemplate'){ } $field = 'template'; +$editor->set_text($data->{$mode}); $editor->use_editor($field, $options); echo '
'; echo ''; @@ -327,6 +329,7 @@ if ($mode == 'listtemplate'){ echo '
'; $field = 'listtemplatefooter'; + $editor->set_text($data->listtemplatefooter); $editor->use_editor($field, $options); echo '
'; echo ''; @@ -338,6 +341,7 @@ if ($mode == 'listtemplate'){ echo '
'; $field = 'rsstitletemplate'; + $editor->set_text($data->rsstitletemplate); $editor->use_editor($field, $options); echo '
'; echo ''; diff --git a/question/behaviour/rendererbase.php b/question/behaviour/rendererbase.php index 0397da02797..0197329af57 100644 --- a/question/behaviour/rendererbase.php +++ b/question/behaviour/rendererbase.php @@ -82,6 +82,7 @@ abstract class qbehaviour_renderer extends plugin_renderer_base { $commenttext = format_text($commenttext, $commentformat, array('para' => false)); + $editor->set_text($commenttext); $editor->use_editor($id, array('context' => $options->context)); $commenteditor = html_writer::tag('div', html_writer::tag('textarea', s($commenttext), diff --git a/question/type/essay/renderer.php b/question/type/essay/renderer.php index 222e2a44410..f8db5516dec 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -236,6 +236,7 @@ class qtype_essay_format_editor_renderer extends plugin_renderer_base { list($draftitemid, $response) = $this->prepare_response_for_editing( $name, $step, $context); + $editor->set_text($response); $editor->use_editor($id, $this->get_editor_options($context), $this->get_filepicker_options($context, $draftitemid));