Commit 50ae8814 authored by Mark Nielsen's avatar Mark Nielsen Committed by Marina Glancy
Browse files

MDL-40248 mod: Allow xxx_get_types() to use default display

* Added new constant: MOD_SUBTYPE_NO_CHILDREN
* When MOD_SUBTYPE_NO_CHILDREN is returned from xxx_get_types()
  then default display is used for activity chooser.
* Updated mod/upgrade.txt
* Removed dead code from navigationlib.php instead of updating
  it for new behavior of xxx_get_types
* Updated lib/upgrade.txt
parent f1351145
......@@ -1289,8 +1289,11 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
$gettypesfunc = $modname.'_get_types';
$types = MOD_SUBTYPE_NO_CHILDREN;
if (function_exists($gettypesfunc)) {
$types = $gettypesfunc();
}
if ($types !== MOD_SUBTYPE_NO_CHILDREN) {
if (is_array($types) && count($types) > 0) {
$group = new stdClass();
$group->name = $modname;
......@@ -1314,7 +1317,9 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
// should have the same archetype
$group->archetype = $subtype->archetype;
if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
if (!empty($type->help)) {
$subtype->help = $type->help;
} else if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
$subtype->help = get_string('help' . $subtype->name, $modname);
}
$subtype->link = new moodle_url($urlbase, array('add' => $modname, 'type' => $subtype->name));
......
......@@ -442,6 +442,9 @@ define('MOD_ARCHETYPE_ASSIGNMENT', 2);
/** System (not user-addable) module archetype */
define('MOD_ARCHETYPE_SYSTEM', 3);
/** Return this from modname_get_types callback to use default display in activity chooser */
define('MOD_SUBTYPE_NO_CHILDREN', 'modsubtypenochildren');
/**
* Security token used for allowing access
* from external application such as web services.
......
......@@ -3522,55 +3522,6 @@ class settings_navigation extends navigation_node {
return $node;
}
/**
* Generate the list of modules for the given course.
*
* @param stdClass $course The course to get modules for
*/
protected function get_course_modules($course) {
global $CFG;
// This function is included when we include course/lib.php at the top
// of this file
$modnames = get_module_types_names();
$resources = array();
$activities = array();
foreach($modnames as $modname=>$modnamestr) {
if (!course_allowed_module($course, $modname)) {
continue;
}
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
if (!file_exists($libfile)) {
continue;
}
include_once($libfile);
$gettypesfunc = $modname.'_get_types';
if (function_exists($gettypesfunc)) {
$types = $gettypesfunc();
foreach($types as $type) {
if (!isset($type->modclass) || !isset($type->typestr)) {
debugging('Incorrect activity type in '.$modname);
continue;
}
if ($type->modclass == MOD_CLASS_RESOURCE) {
$resources[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
} else {
$activities[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr;
}
}
} else {
$archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
if ($archetype == MOD_ARCHETYPE_RESOURCE) {
$resources[$modname] = $modnamestr;
} else {
// all other archetypes are considered activity
$activities[$modname] = $modnamestr;
}
}
}
return array($resources, $activities);
}
/**
* This function loads the course settings that are available for the user
*
......
......@@ -96,6 +96,8 @@ Navigation:
* print_navigation() -> $OUTPUT->navbar()
* build_navigation() -> $PAGE->navbar methods
* navmenu() -> (no replacement)
* settings_navigation::
get_course_modules() -> (no replacement)
Calendar:
* add_event() -> calendar_event::create()
......
This files describes API changes in /mod/* - activity modules,
information provided here is intended especially for developers.
=== 2.6 ===
* xxx_get_types() module callback can now return subtypes that have
a custom help text set. Also instead of array it can now return
MOD_SUBTYPE_NO_CHILDREN. This is optional and still defaults to prior
behavior. See get_module_metadata() in course/lib.php for details.
=== 2.5 ===
......
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