Commit f89c53f6 authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-37085 Substitute get_print_section_cm_text() with cm_info functions

parent f558b291
......@@ -41,8 +41,8 @@ class block_site_main_menu extends block_list {
continue;
}
list($content, $instancename) =
get_print_section_cm_text($cm, $course);
$content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$instancename = $cm->get_formatted_name();
if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
......@@ -111,8 +111,8 @@ class block_site_main_menu extends block_list {
'<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
list($content, $instancename) =
get_print_section_cm_text($modinfo->cms[$modnumber], $course);
$content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$instancename = $mod->get_formatted_name();
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!($url = $mod->get_url())) {
......
......@@ -43,8 +43,8 @@ class block_social_activities extends block_list {
continue;
}
list($content, $instancename) =
get_print_section_cm_text($cm, $course);
$content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$instancename = $cm->get_formatted_name();
if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
......@@ -113,8 +113,8 @@ class block_social_activities extends block_list {
'<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
list($content, $instancename) =
get_print_section_cm_text($modinfo->cms[$modnumber], $course);
$content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$instancename = $mod->get_formatted_name();
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
......
......@@ -1307,42 +1307,18 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
*
* Calls format_text or format_string as appropriate, and obtains the correct icon.
*
* @deprecated since 2.5
*
* This data is also used in other areas of the code.
* @param cm_info $cm Course-module data (must come from get_fast_modinfo)
* @param object $course Moodle course object
* @param object $course (argument not used)
* @return array An array with the following values in this order:
* $content (optional extra content for after link),
* $instancename (text of link)
*/
function get_print_section_cm_text(cm_info $cm, $course) {
global $OUTPUT;
// Get content from modinfo if specified. Content displays either
// in addition to the standard link (below), or replaces it if
// the link is turned off by setting ->url to null.
if (($content = $cm->get_content()) !== '') {
// Improve filter performance by preloading filter setttings for all
// activities on the course (this does nothing if called multiple
// times)
filter_preload_activities($cm->get_modinfo());
// Get module context
$modulecontext = context_module::instance($cm->id);
$labelformatoptions = new stdClass();
$labelformatoptions->noclean = true;
$labelformatoptions->overflowdiv = true;
$labelformatoptions->context = $modulecontext;
$content = format_text($content, FORMAT_HTML, $labelformatoptions);
} else {
$content = '';
}
// Get course context
$coursecontext = context_course::instance($course->id);
$stringoptions = new stdClass;
$stringoptions->context = $coursecontext;
$instancename = format_string($cm->name, true, $stringoptions);
return array($content, $instancename);
return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
$cm->get_formatted_name());
}
/**
......@@ -1463,7 +1439,8 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
echo html_writer::start_tag('div', array('class' => $indentclasses));
// Get data about this course-module
list($content, $instancename) = get_print_section_cm_text($mod, $course);
$content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
$instancename = $mod->get_formatted_name();
//Accessibility: for files get description via icon, this is very ugly hack!
$altname = '';
......
......@@ -756,6 +756,52 @@ class cm_info extends stdClass {
return $this->content;
}
/**
* Returns the content to display on course/overview page, formatted and passed through filters
*
* if $options['context'] is not specified, the module context is used
*
* @param array|stdClass $options formatting options, see {@link format_text()}
* @return string
*/
public function get_formatted_content($options = array()) {
$this->obtain_view_data();
if (empty($this->content)) {
return '';
}
if ($this->modname === 'label') {
// special case, label returns already formatted content, see cm_info::__construct()
// and label_get_coursemodule_info()
return $this->content;
}
// Improve filter performance by preloading filter setttings for all
// activities on the course (this does nothing if called multiple
// times)
filter_preload_activities($this->get_modinfo());
$options = (array)$options;
if (!isset($options['context'])) {
$options['context'] = context_module::instance($this->id);
}
return format_text($this->content, FORMAT_HTML, $options);
}
/**
* Returns the name to display on course/overview page, formatted and passed through filters
*
* if $options['context'] is not specified, the module context is used
*
* @param array|stdClass $options formatting options, see {@link format_string()}
* @return string
*/
public function get_formatted_name($options = array()) {
$options = (array)$options;
if (!isset($options['context'])) {
$options['context'] = context_module::instance($this->id);
}
return format_string($this->name, true, $options);
}
/**
* Note: Will collect view data, if not already obtained.
* @return string Extra CSS classes to add to html output for this activity on main page
......
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