Skip to content

Commit

Permalink
MDL-36985 atto: show file removal text on managefiles plugin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
snake committed Aug 22, 2017
1 parent f3c2afd commit 81ed702
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Expand Up @@ -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';
3 changes: 2 additions & 1 deletion lib/editor/atto/plugins/managefiles/lib.php
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions lib/editor/atto/plugins/managefiles/manage.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -75,7 +76,7 @@
'accepted_types' => $accepted_types,
'areamaxbytes' => $areamaxbytes,
'return_types' => $return_types,
'context' => $context,
'context' => $context
);

$usercontext = context_user::instance($USER->id);
Expand All @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions lib/editor/atto/plugins/managefiles/manage_form.php
Expand Up @@ -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'));

Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/form/editor.php
Expand Up @@ -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 */
Expand Down

0 comments on commit 81ed702

Please sign in to comment.