Commit 8852faea authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-61876 modules: cm_info::set_content can accept formatted text

Allow modules to apply format_text() on user input before calling cm_info::set_content(). This is useful for
modules that add interactive content (for example, JS enhanced folder tree). Otherwise all javascript would
be removed if $CFG->forceclean is enabled.
parent b03c67e9
......@@ -1084,6 +1084,11 @@ class cm_info implements IteratorAggregate {
*/
private $content;
/**
* @var bool
*/
private $contentisformatted;
/**
* @var string
*/
......@@ -1338,6 +1343,10 @@ class cm_info implements IteratorAggregate {
if (empty($this->content)) {
return '';
}
if ($this->contentisformatted) {
return $this->content;
}
// Improve filter performance by preloading filter setttings for all
// activities on the course (this does nothing if called multiple
// times)
......@@ -1619,10 +1628,13 @@ class cm_info implements IteratorAggregate {
/**
* Sets content to display on course view page below link (if present).
* @param string $content New content as HTML string (empty string if none)
* @param bool $isformatted Whether user content is already passed through format_text/format_string and should not
* be formatted again. This can be useful when module adds interactive elements on top of formatted user text.
* @return void
*/
public function set_content($content) {
public function set_content($content, $isformatted = false) {
$this->content = $content;
$this->contentisformatted = $isformatted;
}
/**
......
......@@ -470,7 +470,7 @@ function folder_cm_info_view(cm_info $cm) {
}
// display folder
$renderer = $PAGE->get_renderer('mod_folder');
$cm->set_content($renderer->display_folder($folder));
$cm->set_content($renderer->display_folder($folder), true);
}
}
......
......@@ -134,14 +134,15 @@ class mod_folder_renderer extends plugin_renderer_base {
$filename = $file->get_filename();
$url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(),
$file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename, false);
$filenamedisplay = clean_filename($filename);
if (file_extension_in_typegroup($filename, 'web_image')) {
$image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
$image = html_writer::empty_tag('img', array('src' => $image));
} else {
$image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle');
$image = $this->output->pix_icon(file_file_icon($file, 24), $filenamedisplay, 'moodle');
}
$filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
html_writer::tag('span', $filename, array('class' => 'fp-filename'));
html_writer::tag('span', $filenamedisplay, array('class' => 'fp-filename'));
$filename = html_writer::tag('span',
html_writer::link($url->out(false, array('forcedownload' => 1)), $filename),
array('class' => 'fp-filename-icon'));
......
......@@ -3,8 +3,11 @@ information provided here is intended especially for developers.
=== 3.5 ===
Required changes in code:
* use new make_backup_temp_directory()
* Backup directory now can be outside of temp directory. Use make_backup_temp_directory($name) instead of
make_temp_directory('/backup/'.$name)
* Modules that provide their own interactive content and call cm_info::set_content() from [MODULENAME]_cm_info_view()
callback should format all user input and call set_content() with parameter $isformatted=true . Otherwise
scripts will be cleaned on the course page in case of $CFG->forceclean=1. See example in mod_folder.
=== 3.4 ===
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment