diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 39d4f157e9c..95a5ea1c1d5 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -156,7 +156,19 @@ class mod_lti_mod_form extends moodleform_mod { } $mform->addHelpButton('typeid', 'external_tool_type', 'lti'); - foreach (lti_get_types_for_add_instance() as $id => $type) { + // To prevent the use of manually configured instances, existing instances which are using a preconfigured tool will not + // display the option "Automatic, based on tool URL" in the preconfigured tools select. This prevents switching from an + // instance configured using a preconfigured tool to an instance that is manually configured. + // Exceptions are made for: + // - Existing manually configured instances (i.e. no type set). + // - Instances using a tool type which isn't visible in the course preconfigured tools selector, such as when a + // site-level tool type is domain-matched. + $instancetypes = lti_get_types_for_add_instance(); + if (!empty($this->current->typeid) && array_key_exists($this->current->typeid, $instancetypes)) { + unset($instancetypes[0]); + } + + foreach ($instancetypes as $id => $type) { if (!empty($type->toolproxyid)) { $toolproxy[] = $type->id; $attributes = array('globalTool' => 1, 'toolproxy' => 1); diff --git a/mod/lti/tests/behat/addtool.feature b/mod/lti/tests/behat/addtool.feature index ebfd359e2ee..32233c6a800 100644 --- a/mod/lti/tests/behat/addtool.feature +++ b/mod/lti/tests/behat/addtool.feature @@ -56,3 +56,5 @@ Feature: Add tools Then the field "Preconfigured tool" matches value "Course tool 1" And the "Select content" "button" should be disabled And the "Tool URL" "field" should be disabled + And I click on "Preconfigured tool" "select" + And I should not see "Automatic, based on tool URL"