MDL-62815 mod_lti: fix error when clicking 'Select content' option

This commit is contained in:
Davo Smith 2019-07-24 10:55:52 +01:00
parent dcb0f01f58
commit b791ed15e2
2 changed files with 20 additions and 4 deletions

View File

@ -538,11 +538,20 @@
* @returns {number|boolean} The ID of the tool type if it supports Content-Item selection. False, otherwise.
*/
getContentItemId: function() {
var selected = this.getSelectedToolTypeOption();
if (selected.getAttribute('data-contentitem')) {
return selected.getAttribute('data-id');
try {
var selected = this.getSelectedToolTypeOption();
if (selected.getAttribute('data-contentitem')) {
return selected.getAttribute('data-id');
}
return false;
} catch (err) {
// Tool selector not available - check for hidden fields instead.
var content = Y.one('input[name="contentitem"]');
if (!content || !content.get('value')) {
return false;
}
return Y.one('input[name="typeid"]').get('value');
}
return false;
},
/**

View File

@ -162,6 +162,13 @@ class mod_lti_mod_form extends moodleform_mod {
} else {
$mform->addElement('hidden', 'typeid', $typeid);
$mform->setType('typeid', PARAM_INT);
if ($typeid) {
$config = lti_get_type_config($typeid);
if (!empty($config['contentitem'])) {
$mform->addElement('hidden', 'contentitem', 1);
$mform->setType('contentitem', PARAM_INT);
}
}
}
// Add button that launches the content-item selection dialogue.