MDL-62815 mod_lti: fix error when clicking 'Select content' option
authorDavo Smith <davo.smith@synergy-learning.com>
Wed, 24 Jul 2019 09:55:52 +0000 (10:55 +0100)
committerDavo Smith <davo.smith@synergy-learning.com>
Wed, 8 Jan 2020 09:46:41 +0000 (09:46 +0000)
mod/lti/mod_form.js
mod/lti/mod_form.php

index a14ac91..2b21157 100644 (file)
          * @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;
         },
 
         /**
index 1a6fdd8..8eb9fac 100644 (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.