Skip to content

Commit e078082

Browse files
MDL-85844 core_ltix: Allow default state config for LTI placements
Adds support for configuring the default state of placements during LTI tool creation. This setting applies only to site-level tools.
1 parent 468af88 commit e078082

5 files changed

Lines changed: 27 additions & 6 deletions

File tree

lang/en/ltix.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
$string['keytype_keyset'] = 'Keyset URL';
133133
$string['keytype_rsa'] = 'RSA key';
134134
$string['lti_administration'] = 'Edit preconfigured tool';
135+
$string['lti_default_usage'] = 'Default state';
136+
$string['lti_default_usage_help'] = 'If set, this placement will be enabled by default.';
135137
$string['lti_deeplinkingurl'] = 'Deep Linking Request URL';
136138
$string['lti_deeplinkingurl_help'] = 'If set, this URL will be used to launch the tool for deep linking requests.';
137139
$string['lti_placementtext'] = 'Text';

ltix/classes/form/edit_types.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ protected function add_placement_config_elements(\MoodleQuickForm &$mform, int $
400400
// In the future we will have more placement types, so use a suffix to avoid duplicate element names.
401401
$suffix = "_placementconfig{$placementtypeid}"; // Use placement type id as suffix.
402402

403+
if (!$this->_customdata->iscoursetool) {
404+
$mform->addElement('advcheckbox', 'default_usage' . $suffix,
405+
get_string('lti_default_usage', 'core_ltix'), get_string('active'), null, ['disabled', 'enabled']);
406+
$mform->setType('default_usage' . $suffix, PARAM_ALPHA);
407+
$mform->addHelpButton('default_usage' . $suffix, 'lti_default_usage', 'core_ltix');
408+
}
409+
403410
$mform->addElement('text', 'deep_linking_url' . $suffix,
404411
get_string('lti_deeplinkingurl', 'core_ltix'), ['size' => '64']);
405412
$mform->setType('deep_linking_url' . $suffix, PARAM_URL);

ltix/classes/helper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,10 @@ public static function update_placement_config(object $type, object $config): vo
13851385
ARRAY_FILTER_USE_BOTH
13861386
);
13871387

1388-
// Disabled if there are no config for this placement type.
1389-
$placementconfig["default_usage{$elementsuffix}"] = empty($placementconfig) ? 'disabled' : 'enabled';
1388+
// Placements should have the default_usage config set. If not set, set it to 'enabled' (e.g., for course tool).
1389+
if (!isset($placementconfig["default_usage{$elementsuffix}"])) {
1390+
$placementconfig["default_usage{$elementsuffix}"] = 'enabled';
1391+
}
13901392

13911393
// Save the config values.
13921394
foreach ($placementconfig as $name => $value) {

ltix/tests/behat/placementsconfigure.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Feature: Configure placements for a tool
1414
And I expand the "Placements" autocomplete
1515
And I should see "Activity chooser" in the "Placements" "autocomplete"
1616
And the following fields in the "Placement: Activity chooser" "fieldset" match these values:
17+
| Default state | |
1718
| Deep Linking Request URL | |
1819
| Resource Linking Request URL | |
1920
| Icon URL | |
@@ -29,6 +30,7 @@ Feature: Configure placements for a tool
2930
And I click on "Edit" "link"
3031
When I set the field "Placements" in the "Placement" "fieldset" to "Activity chooser"
3132
And I set the following fields in the "Placement: Activity chooser" "fieldset" to these values:
33+
| Default state | 1 |
3234
| Deep Linking Request URL | http://deep.link |
3335
| Resource Linking Request URL | http://resource.link |
3436
| Icon URL | https://icon |
@@ -37,6 +39,7 @@ Feature: Configure placements for a tool
3739
And I click on "Edit" "link"
3840
Then "Activity chooser" "autocomplete_selection" should exist in the "Placement" "fieldset"
3941
And the following fields in the "Placement: Activity chooser" "fieldset" match these values:
42+
| Default state | 1 |
4043
| Deep Linking Request URL | http://deep.link |
4144
| Resource Linking Request URL | http://resource.link |
4245
| Icon URL | https://icon |
@@ -82,19 +85,21 @@ Feature: Configure placements for a tool
8285
| name | baseurl |
8386
| Site Tool 1 | /ltix/tests/fixtures/tool_provider.php |
8487
And the following "core_ltix > tool placements" exist:
85-
| tool | placementtype | config_deep_linking_url | config_icon_url | config_text |
86-
| Site Tool 1 | mod_lti:activityplacement | http://deeplink | https://icon | Some text for the tool |
88+
| tool | placementtype | config_default_usage | config_deep_linking_url | config_icon_url | config_text |
89+
| Site Tool 1 | mod_lti:activityplacement | 1 | http://deeplink | https://icon | Some text for the tool |
8790
And I log in as "admin"
8891
And I navigate to "LTI > Manage tools" in site administration
8992
And I click on "Edit" "link"
9093
# Edit several configuration options for the 'Activity chooser' placement and verify the changes are applied.
9194
When I set the following fields in the "Placement: Activity chooser" "fieldset" to these values:
95+
| Default state | |
9296
| Deep Linking Request URL | http://deep.link.updated |
9397
| Text | Some text for the tool (edited) |
9498
And I press "Save changes"
9599
And I click on "Edit" "link"
96100
Then "Activity chooser" "autocomplete_selection" should exist in the "Placement" "fieldset"
97101
And the following fields in the "Placement: Activity chooser" "fieldset" match these values:
102+
| Default state | |
98103
| Deep Linking Request URL | http://deep.link.updated |
99104
| Resource Linking Request URL | |
100105
| Icon URL | https://icon |
@@ -105,6 +110,7 @@ Feature: Configure placements for a tool
105110
And I click on "Edit" "link"
106111
And "Activity chooser" "autocomplete_selection" should not exist in the "Placement" "fieldset"
107112
And the following fields in the "Placement: Activity chooser" "fieldset" match these values:
113+
| Default state | |
108114
| Deep Linking Request URL | |
109115
| Resource Linking Request URL | |
110116
| Icon URL | |

ltix/tests/helper_test.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ public static function load_placement_config_provider(): array {
14851485
[
14861486
'placementtypeid' => 2,
14871487
'configdata' => [
1488+
'default_usage' => 'enabled',
14881489
'resource_linking_url' => 'http://resourcelink.example.com',
14891490
'icon_url' => 'https://icon2.example.com',
14901491
'text' => 'Example text',
@@ -1493,6 +1494,7 @@ public static function load_placement_config_provider(): array {
14931494
[
14941495
'placementtypeid' => 3,
14951496
'configdata' => [
1497+
'default_usage' => 'disabled',
14961498
'deep_linking_url' => 'http://deeplink3.example.com',
14971499
'resource_linking_url' => 'http://resourcelink3.example.com',
14981500
'icon_url' => 'https://icon3.example.com',
@@ -1508,12 +1510,12 @@ public static function load_placement_config_provider(): array {
15081510
'resource_linking_url_placementconfig2' => 'http://resourcelink.example.com',
15091511
'icon_url_placementconfig2' => 'https://icon2.example.com',
15101512
'text_placementconfig2' => 'Example text',
1511-
'default_usage_placementconfig2' => 'enabled', // Set by create_tool_placements() generator function.
1513+
'default_usage_placementconfig2' => 'enabled',
15121514
'deep_linking_url_placementconfig3' => 'http://deeplink3.example.com',
15131515
'resource_linking_url_placementconfig3' => 'http://resourcelink3.example.com',
15141516
'icon_url_placementconfig3' => 'https://icon3.example.com',
15151517
'text_placementconfig3' => 'Example text 3',
1516-
'default_usage_placementconfig3' => 'enabled', // Set by create_tool_placements() generator function.
1518+
'default_usage_placementconfig3' => 'disabled',
15171519
],
15181520
],
15191521
'No tool placements' =>
@@ -1628,6 +1630,7 @@ public static function delete_tool_placements_by_type_provider(): array {
16281630
[
16291631
'placementtypeid' => 3,
16301632
'configdata' => [
1633+
'default_usage' => 'enabled',
16311634
'deep_linking_url' => 'http://deeplink3.example.com',
16321635
'resource_linking_url' => 'http://resourcelink3.example.com',
16331636
'icon_url' => 'https://icon3.example.com',
@@ -1658,6 +1661,7 @@ public static function delete_tool_placements_by_type_provider(): array {
16581661
[
16591662
'placementtypeid' => 3,
16601663
'configdata' => [
1664+
'default_usage' => 'disabled',
16611665
'deep_linking_url' => 'http://deeplink3.example.com',
16621666
'resource_linking_url' => 'http://resourcelink3.example.com',
16631667
'icon_url' => 'https://icon3.example.com',

0 commit comments

Comments
 (0)