Skip to content

Commit

Permalink
MDL-40248 mod: Allow xxx_get_types() to use default display
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
polothy authored and marinaglancy committed Sep 30, 2013
1 parent f135114 commit 50ae881
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 50 deletions.
7 changes: 6 additions & 1 deletion course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@
/** 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.
Expand Down
49 changes: 0 additions & 49 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3522,55 +3522,6 @@ protected function get_by_path(array $path) {
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
*
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions mod/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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 ===

Expand Down

0 comments on commit 50ae881

Please sign in to comment.