Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-27001 'Show description' feature part 2 - Automatic support for m…

…odules that don't have a get_coursemodule_info function

If a module doesn't have module_get_coursemodule_info function, but it does have 'intro' and 'introformat' fields in its main table, then all it needs to do is return true for FEATURE_SHOW_DESCRIPTIONS and everything is handled automatically.
  • Loading branch information...
commit b3a89232d9853539fdc3ea7da47dd2cfece7b734 1 parent 8c40662
@sammarshallou sammarshallou authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 course/lib.php
View
17 course/lib.php
@@ -1122,7 +1122,7 @@ function get_array_of_activities($courseid) {
include_once("$CFG->dirroot/mod/$modname/lib.php");
- if (function_exists($functionname)) {
+ if ($hasfunction = function_exists($functionname)) {
if ($info = $functionname($rawmods[$seq])) {
if (!empty($info->icon)) {
$mod[$seq]->icon = $info->icon;
@@ -1157,6 +1157,21 @@ function get_array_of_activities($courseid) {
}
}
}
+ // When there is no modname_get_coursemodule_info function,
+ // but showdescriptions is enabled, then we use the 'intro'
+ // and 'introformat' fields in the module table
+ if (!$hasfunction && $rawmods[$seq]->showdescription) {
+ if ($modvalues = $DB->get_record($rawmods[$seq]->modname,
+ array('id' => $rawmods[$seq]->instance), 'name, intro, introformat')) {
+ // Set content from intro and introformat. Filters are disabled
+ // because we filter it with format_text at display time
+ $mod[$seq]->content = format_module_intro($rawmods[$seq]->modname,
+ $modvalues, $rawmods[$seq]->id, false);
+
+ // To save making another query just below, put name in here
+ $mod[$seq]->name = $modvalues->name;
+ }
+ }
if (!isset($mod[$seq]->name)) {
$mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance));
}
Please sign in to comment.
Something went wrong with that request. Please try again.