Commit 2348c137 authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-45064 mod_lti: use callback get_shortcuts()

deprecate callback for ltisource plugins get_types(), instead introduce
get_shortcuts()
parent 9ca0420e
...@@ -198,60 +198,51 @@ function lti_delete_instance($id) { ...@@ -198,60 +198,51 @@ function lti_delete_instance($id) {
/** /**
* Return aliases of this activity. LTI should have an alias for each configured tool type * Return aliases of this activity. LTI should have an alias for each configured tool type
* This is so you can add an external tool types directly from the activity chooser * This is so you can add an external tool types directly to the activity chooser
* *
* @return array An array of aliases for this activity * @param stdClass $defaultitem default item that would be added to the activity chooser if this callback was not present.
* It has properties: archetype, name, title, help, icon, link
* @return array An array of aliases for this activity. Each element is an object with same list of properties as $defaultitem.
* Properties title and link are required
**/ **/
function lti_get_aliases() { function lti_get_shortcuts($defaultitem) {
global $CFG, $COURSE; global $CFG, $COURSE;
require_once($CFG->dirroot.'/mod/lti/locallib.php'); require_once($CFG->dirroot.'/mod/lti/locallib.php');
$types = lti_get_configured_types($COURSE->id); $types = lti_get_configured_types($COURSE->id, $defaultitem->link->param('sr'));
$types[] = $defaultitem;
return $types;
} // Add items defined in ltisource plugins.
foreach (core_component::get_plugin_list('ltisource') as $pluginname => $dir) {
function lti_get_types() { if ($moretypes = component_callback("ltisource_$pluginname", 'get_types')) {
global $OUTPUT; // 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 .
$subtypes = array(); ', use get_shortcuts() instead', DEBUG_DEVELOPER);
foreach (get_plugin_list('ltisource') as $name => $dir) { $grouptitle = get_string('modulenameplural', 'mod_lti');
if ($moretypes = component_callback("ltisource_$name", 'get_types')) { foreach ($moretypes as $subtype) {
$subtypes = array_merge($subtypes, $moretypes); // 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.
if ($moretypes = component_callback("ltisource_$pluginname", 'get_shortcuts', array($defaultitem))) {
$types = array_merge($types, $moretypes);
} }
} }
if (empty($subtypes)) {
return MOD_SUBTYPE_NO_CHILDREN;
}
$types = array();
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = 'lti_group_start';
$type->typestr = '--'.get_string('modulenameplural', 'mod_lti');
$types[] = $type;
$link = get_string('modulename_link', 'mod_lti');
$linktext = get_string('morehelp');
$help = get_string('modulename_help', 'mod_lti');
$help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = '';
$type->typestr = get_string('generaltool', 'mod_lti');
$type->help = $help;
$types[] = $type;
$types = array_merge($types, $subtypes);
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->type = 'lti_group_end';
$type->typestr = '--';
$types[] = $type;
return $types; return $types;
} }
......
...@@ -1074,7 +1074,7 @@ function lti_filter_tool_types(array $tools, $state) { ...@@ -1074,7 +1074,7 @@ function lti_filter_tool_types(array $tools, $state) {
* Returns all lti types visible in this course * Returns all lti types visible in this course
* *
* @param int $courseid The id of the course to retieve types for * @param int $courseid The id of the course to retieve types for
* @return stdClass All the lti types visible in the given course * @return stdClass[] All the lti types visible in the given course
*/ */
function lti_get_lti_types_by_course($courseid) { function lti_get_lti_types_by_course($courseid) {
global $DB, $SITE; global $DB, $SITE;
...@@ -1112,9 +1112,10 @@ function lti_get_types_for_add_instance() { ...@@ -1112,9 +1112,10 @@ function lti_get_types_for_add_instance() {
* Returns a list of configured types in the given course * Returns a list of configured types in the given course
* *
* @param int $courseid The id of the course to retieve types for * @param int $courseid The id of the course to retieve types for
* @return array Array of lti types * @param int $sectionreturn section to return to for forming the URLs
* @return array Array of lti types. Each element is object with properties: name, title, icon, help, link
*/ */
function lti_get_configured_types($courseid) { function lti_get_configured_types($courseid, $sectionreturn = 0) {
global $OUTPUT; global $OUTPUT;
$types = array(); $types = array();
$admintypes = lti_get_lti_types_by_course($courseid); $admintypes = lti_get_lti_types_by_course($courseid);
...@@ -1129,11 +1130,8 @@ function lti_get_configured_types($courseid) { ...@@ -1129,11 +1130,8 @@ function lti_get_configured_types($courseid) {
} else { } else {
$type->icon = html_writer::empty_tag('img', array('src' => $ltitype->icon, 'alt' => $ltitype->name, 'class' => 'icon')); $type->icon = html_writer::empty_tag('img', array('src' => $ltitype->icon, 'alt' => $ltitype->name, 'class' => 'icon'));
} }
if (!empty($ltitype->description)) { $type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'course' => $courseid,
$type->help = $ltitype->description; 'sr' => $sectionreturn, 'typeid' => $ltitype->id));
}
$type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'course' => $courseid, 'sr' => 0,
'typeid' => $ltitype->id));
$types[] = $type; $types[] = $type;
} }
return $types; return $types;
......
This files describes API changes in /mod/lti/source/* - LTI source plugins,
information provided here is intended especially for developers.
=== 3.1 ===
* Callback get_types() is deprecated, instead ltisource plugins can define callback get_shortcuts().
See source code for lti_get_shortcuts() and get_module_metadata().
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