From b791ed15e2d6e92be71530ead3257a61d2bd036a Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Wed, 24 Jul 2019 10:55:52 +0100 Subject: [PATCH] MDL-62815 mod_lti: fix error when clicking 'Select content' option --- mod/lti/mod_form.js | 17 +++++++++++++---- mod/lti/mod_form.php | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js index a14ac91a316..2b21157bcba 100644 --- a/mod/lti/mod_form.js +++ b/mod/lti/mod_form.js @@ -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; }, /** diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 1a6fdd870c9..8eb9fac73f9 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -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. -- 2.43.0