Skip to content

Commit

Permalink
MDL-53697 mod: Final deprecation of xxx_get_types().
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Jul 12, 2018
1 parent f61ee4e commit 4bebed4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 81 deletions.
3 changes: 1 addition & 2 deletions course/format/singleactivity/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ protected function can_add_activity() {

/**
* Checks if the activity type has multiple items in the activity chooser.
* This may happen as a result of defining callback modulename_get_shortcuts()
* or [deprecated] modulename_get_types() - TODO MDL-53697 remove this line.
* This may happen as a result of defining callback modulename_get_shortcuts().
*
* @return bool|null (null if the check is not possible)
*/
Expand Down
53 changes: 3 additions & 50 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,6 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
}
$defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);

// Legacy support for callback get_types() - do not use any more, use get_shortcuts() instead!
$typescallbackexists = component_callback_exists($modname, 'get_types');

// Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
// of elements to be added to activity chooser.
$items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
Expand Down Expand Up @@ -699,58 +696,14 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
$modlist[$course->id][$modname][$item->name] = $item;
}
$return += $modlist[$course->id][$modname];
if ($typescallbackexists) {
debugging('Both callbacks get_shortcuts() and get_types() are found in module ' . $modname .
'. Callback get_types() will be completely ignored', DEBUG_DEVELOPER);
}
// If get_shortcuts() callback is defined, the default module action is not added.
// It is a responsibility of the callback to add it to the return value unless it is not needed.
continue;
}

if ($typescallbackexists) {
debugging('Callback get_types() is found in module ' . $modname . ', this functionality is deprecated, ' .
'please use callback get_shortcuts() instead', DEBUG_DEVELOPER);
}
$types = component_callback($modname, 'get_types', array(), MOD_SUBTYPE_NO_CHILDREN);
if ($types !== MOD_SUBTYPE_NO_CHILDREN) {
// Legacy support for deprecated callback get_types(). To be removed in Moodle 3.5. TODO MDL-53697.
if (is_array($types) && count($types) > 0) {
$grouptitle = $modnamestr;
$icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
foreach($types as $type) {
if ($type->typestr === '--') {
continue;
}
if (strpos($type->typestr, '--') === 0) {
$grouptitle = str_replace('--', '', $type->typestr);
continue;
}
// Set the Sub Type metadata.
$subtype = new stdClass();
$subtype->title = get_string('activitytypetitle', '',
(object)['activity' => $grouptitle, 'type' => $type->typestr]);
$subtype->type = str_replace('&', '&', $type->type);
$typename = preg_replace('/.*type=/', '', $subtype->type);
$subtype->archetype = $type->modclass;

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' => $typename));
$subtype->name = $modname . ':' . $subtype->link;
$subtype->icon = $icon;
$modlist[$course->id][$modname][$subtype->name] = $subtype;
}
$return += $modlist[$course->id][$modname];
}
} else {
// Neither get_shortcuts() nor get_types() callbacks found, use the default item for the activity chooser.
$modlist[$course->id][$modname][$modname] = $defaultmodule;
$return[$modname] = $defaultmodule;
}
// The callback get_shortcuts() was not found, use the default item for the activity chooser.
$modlist[$course->id][$modname][$modname] = $defaultmodule;
$return[$modname] = $defaultmodule;
}

core_collator::asort_objects_by_property($return, 'title');
Expand Down
7 changes: 0 additions & 7 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,6 @@
/** 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.
* Deprecated, will be removed in 3.5, TODO MDL-53697.
* @deprecated since Moodle 3.1
*/
define('MOD_SUBTYPE_NO_CHILDREN', 'modsubtypenochildren');

/**
* Security token used for allowing access
* from external application such as web services.
Expand Down
22 changes: 0 additions & 22 deletions mod/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,6 @@ function lti_get_shortcuts($defaultitem) {

// Add items defined in ltisource plugins.
foreach (core_component::get_plugin_list('ltisource') as $pluginname => $dir) {
if ($moretypes = component_callback("ltisource_$pluginname", 'get_types')) {
// Callback 'get_types()' in 'ltisource' plugins is deprecated in 3.1 and will be removed in 3.5, TODO MDL-53697.
debugging('Deprecated callback get_types() is found in ltisource_' . $pluginname .
', use get_shortcuts() instead', DEBUG_DEVELOPER);
$grouptitle = get_string('modulenameplural', 'mod_lti');
foreach ($moretypes as $subtype) {
// Instead of adding subitems combine the name of the group with the name of the subtype.
$subtype->title = get_string('activitytypetitle', '',
(object)['activity' => $grouptitle, 'type' => $subtype->typestr]);
// Re-implement the logic of get_module_metadata() in Moodle 3.0 and below for converting
// subtypes into items in activity chooser.
$subtype->type = str_replace('&', '&', $subtype->type);
$subtype->name = preg_replace('/.*type=/', '', $subtype->type);
$subtype->link = new moodle_url($defaultitem->link, array('type' => $subtype->name));
if (empty($subtype->help) && !empty($subtype->name) &&
get_string_manager()->string_exists('help' . $subtype->name, $pluginname)) {
$subtype->help = get_string('help' . $subtype->name, $pluginname);
}
unset($subtype->typestr);
$types[] = $subtype;
}
}
// LTISOURCE plugins can also implement callback get_shortcuts() to add items to the activity chooser.
// The return values are the same as of the 'mod' callbacks except that $defaultitem is only passed for reference and
// should not be added to the return value.
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.

=== 3.6 ===

* The final deprecation of xxx_get_types() callback means that this function will no longer be called.
Please use get_shortcuts() instead.
* lti_get_shortcuts has been deprecated. Please use get_shortcuts() instead to add items to the activity chooser.

=== 3.5 ===

* There is a new privacy API that every subsystem and plugin has to implement so that the site can become GDPR
Expand Down

0 comments on commit 4bebed4

Please sign in to comment.