From 81ed702156743ccd8f666e0639c9d238fd4c4554 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Thu, 17 Aug 2017 16:39:09 +0800 Subject: [PATCH] MDL-36985 atto: show file removal text on managefiles plugin Shows a text warning in the manage files plugin window when an editor has set the 'removeorphaneddrafts' option to true. The text tells the user that unused files will be automatically deleted on save. --- .../atto/plugins/managefiles/lang/en/atto_managefiles.php | 1 + lib/editor/atto/plugins/managefiles/lib.php | 3 ++- lib/editor/atto/plugins/managefiles/manage.php | 7 ++++--- lib/editor/atto/plugins/managefiles/manage_form.php | 7 +++++++ lib/form/editor.php | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/editor/atto/plugins/managefiles/lang/en/atto_managefiles.php b/lib/editor/atto/plugins/managefiles/lang/en/atto_managefiles.php index 53db50bd91887..f98243e01912a 100644 --- a/lib/editor/atto/plugins/managefiles/lang/en/atto_managefiles.php +++ b/lib/editor/atto/plugins/managefiles/lang/en/atto_managefiles.php @@ -29,4 +29,5 @@ $string['missingfiles'] = 'Missing files'; $string['pluginname'] = 'Manage files'; $string['unusedfilesdesc'] = 'The following embedded files are not used in the text area:'; +$string['unusedfilesremovalnotice'] = 'Any unused files will be automatically deleted when saving changes.'; $string['unusedfilesheader'] = 'Unused files'; diff --git a/lib/editor/atto/plugins/managefiles/lib.php b/lib/editor/atto/plugins/managefiles/lib.php index bce1bd469fe60..b6ff2a1a259d8 100644 --- a/lib/editor/atto/plugins/managefiles/lib.php +++ b/lib/editor/atto/plugins/managefiles/lib.php @@ -55,7 +55,8 @@ function atto_managefiles_params_for_js($elementid, $options, $fpoptions) { if (!$disabled) { $params['usercontext'] = context_user::instance($USER->id)->id; - foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) { + foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types', + 'removeorphaneddrafts') as $key) { if (isset($options[$key])) { if ($key === 'context' && is_object($options[$key])) { // Just context id is enough. diff --git a/lib/editor/atto/plugins/managefiles/manage.php b/lib/editor/atto/plugins/managefiles/manage.php index ff6922bdf5648..5dd39a4948172 100644 --- a/lib/editor/atto/plugins/managefiles/manage.php +++ b/lib/editor/atto/plugins/managefiles/manage.php @@ -35,6 +35,7 @@ $areamaxbytes = optional_param('areamaxbytes', FILE_AREA_MAX_BYTES_UNLIMITED, PARAM_INT); $contextid = optional_param('context', SYSCONTEXTID, PARAM_INT); $elementid = optional_param('elementid', '', PARAM_TEXT); +$removeorphaneddrafts = optional_param('removeorphaneddrafts', 0, PARAM_INT); $context = context::instance_by_id($contextid); if ($context->contextlevel == CONTEXT_MODULE) { @@ -75,7 +76,7 @@ 'accepted_types' => $accepted_types, 'areamaxbytes' => $areamaxbytes, 'return_types' => $return_types, - 'context' => $context, + 'context' => $context ); $usercontext = context_user::instance($USER->id); @@ -87,8 +88,8 @@ } $mform = new atto_managefiles_manage_form(null, - array('options' => $options, 'draftitemid' => $itemid, 'files' => $filenames, 'elementid' => $elementid), - 'post', '', array('id' => 'atto_managefiles_manageform')); + array('options' => $options, 'draftitemid' => $itemid, 'files' => $filenames, 'elementid' => $elementid, + 'removeorphaneddrafts' => $removeorphaneddrafts), 'post', '', array('id' => 'atto_managefiles_manageform')); if ($data = $mform->get_data()) { if (!empty($data->deletefile)) { diff --git a/lib/editor/atto/plugins/managefiles/manage_form.php b/lib/editor/atto/plugins/managefiles/manage_form.php index 50bb8dd5dfa15..a5569aa92a583 100644 --- a/lib/editor/atto/plugins/managefiles/manage_form.php +++ b/lib/editor/atto/plugins/managefiles/manage_form.php @@ -47,6 +47,7 @@ function definition() { $elementid = $this->_customdata['elementid']; $options = $this->_customdata['options']; $files = $this->_customdata['files']; + $removeorphaneddrafts = $this->_customdata['removeorphaneddrafts']; $mform->addElement('header', 'filemanagerhdr', get_string('filemanager', 'atto_managefiles')); @@ -69,6 +70,12 @@ function definition() { $mform->addElement('filemanager', 'files_filemanager', '', null, $options); + // Let the user know that any drafts not referenced in the text will be removed automatically. + if ($removeorphaneddrafts) { + $mform->addElement('static', '', '', + html_writer::tag('div', get_string('unusedfilesremovalnotice', 'atto_managefiles'))); + } + $mform->addElement('header', 'missingfileshdr', get_string('missingfiles', 'atto_managefiles')); $mform->addElement('static', '', '', html_writer::tag('div', diff --git a/lib/form/editor.php b/lib/form/editor.php index 69a781272196a..d32527ab3e76e 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -58,7 +58,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatab /** @var array options provided to initalize filepicker */ protected $_options = array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 0, 'changeformat' => 0, 'areamaxbytes' => FILE_AREA_MAX_BYTES_UNLIMITED, 'context' => null, 'noclean' => 0, 'trusttext' => 0, - 'return_types' => 15, 'enable_filemanagement' => true); + 'return_types' => 15, 'enable_filemanagement' => true, 'removeorphaneddrafts' => false); // 15 is $_options['return_types'] = FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK. /** @var array values for editor */