Skip to content

Commit 4a18707

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 09d56a1 commit 4a18707

5 files changed

Lines changed: 38 additions & 9 deletions

File tree

public/lang/en/ltix.php

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

public/ltix/classes/form/edit_types.php

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

408+
if (!$this->_customdata->iscoursetool) {
409+
$mform->addElement('advcheckbox', 'default_usage' . $suffix,
410+
get_string('lti_default_usage', 'core_ltix'), get_string('active'), null, ['disabled', 'enabled']);
411+
$mform->setType('default_usage' . $suffix, PARAM_ALPHA);
412+
$mform->addHelpButton('default_usage' . $suffix, 'lti_default_usage', 'core_ltix');
413+
}
414+
408415
$mform->addElement('text', 'deep_linking_url' . $suffix,
409416
get_string('lti_deeplinkingurl', 'core_ltix'), ['size' => '64']);
410417
$mform->setType('deep_linking_url' . $suffix, PARAM_URL);

public/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) {

public/ltix/tests/behat/placementsconfigure.feature

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Feature: Configure placements for a tool
1818
And I should see "Mock placement" in the "Placements" "autocomplete"
1919
And "Placement: Mock placement" "fieldset" should not be visible
2020
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
21+
| Default state | |
2122
| Deep Linking Request URL | |
2223
| Resource Linking Request URL | |
2324
| Icon URL | |
@@ -37,6 +38,7 @@ Feature: Configure placements for a tool
3738
When I set the field "Placements" in the "Placement" "fieldset" to "Mock placement"
3839
And "Placement: Mock placement" "fieldset" should be visible
3940
And I set the following fields in the "Placement: Mock placement" "fieldset" to these values:
41+
| Default state | 1 |
4042
| Deep Linking Request URL | http://deep.link |
4143
| Resource Linking Request URL | http://resource.link |
4244
| Icon URL | https://icon |
@@ -45,6 +47,7 @@ Feature: Configure placements for a tool
4547
And I click on "Edit" "link"
4648
Then "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
4749
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
50+
| Default state | 1 |
4851
| Deep Linking Request URL | http://deep.link |
4952
| Resource Linking Request URL | http://resource.link |
5053
| Icon URL | https://icon |
@@ -79,9 +82,11 @@ Feature: Configure placements for a tool
7982
| Icon URL | https://icon |
8083
| Text | Some text for the tool |
8184
And I press "Save changes"
85+
# Course tool placement should be enabled by default, so it should show in the Active placements column
86+
Then I should see "Mock placement" in the "Course Tool 1" "table_row"
8287
And I open the action menu in "Course Tool 1" "table_row"
8388
And I choose "Edit" in the open action menu
84-
Then "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
89+
And "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
8590
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
8691
| Deep Linking Request URL | http://deep.link |
8792
| Resource Linking Request URL | http://resource.link |
@@ -97,19 +102,21 @@ Feature: Configure placements for a tool
97102
| placementtype | component |
98103
| core_ltix:mockplacement | core_ltix |
99104
And the following "core_ltix > tool placements" exist:
100-
| tool | placementtype | config_deep_linking_url | config_icon_url | config_text |
101-
| Site Tool 1 | core_ltix:mockplacement | http://deeplink | https://icon | Some text for the tool |
105+
| tool | placementtype | config_default_usage | config_deep_linking_url | config_icon_url | config_text |
106+
| Site Tool 1 | core_ltix:mockplacement | 1 | http://deeplink | https://icon | Some text for the tool |
102107
And I log in as "admin"
103108
And I navigate to "LTI > Manage tools" in site administration
104109
And I click on "Edit" "link"
105110
# Edit several configuration options for the placement and verify the changes are applied.
106111
When I set the following fields in the "Placement: Mock placement" "fieldset" to these values:
112+
| Default state | |
107113
| Deep Linking Request URL | http://deep.link.updated |
108114
| Text | Some text for the tool (edited) |
109115
And I press "Save changes"
110116
And I click on "Edit" "link"
111117
Then "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
112118
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
119+
| Default state | |
113120
| Deep Linking Request URL | http://deep.link.updated |
114121
| Resource Linking Request URL | |
115122
| Icon URL | https://icon |
@@ -121,6 +128,7 @@ Feature: Configure placements for a tool
121128
And "Mock placement" "autocomplete_selection" should not exist in the "Placement" "fieldset"
122129
And "Placement: Mock placement" "fieldset" should not be visible
123130
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
131+
| Default state | |
124132
| Deep Linking Request URL | |
125133
| Resource Linking Request URL | |
126134
| Icon URL | |
@@ -145,7 +153,7 @@ Feature: Configure placements for a tool
145153
| core_ltix:mockplacement | core_ltix |
146154
And the following "core_ltix > tool placements" exist:
147155
| tool | placementtype | config_deep_linking_url | config_icon_url | config_text |
148-
| Course Tool 1 | core_ltix:mockplacement | http://deeplink | https://icon | Some text for the tool |
156+
| Course Tool 1 | core_ltix:mockplacement | http://deeplink | https://icon | Some text for the tool |
149157
And I am on the "Course 1" course page logged in as teacher1
150158
And I navigate to "LTI External tools" in current page administration
151159
And I open the action menu in "Course Tool 1" "table_row"
@@ -155,9 +163,11 @@ Feature: Configure placements for a tool
155163
| Deep Linking Request URL | http://deep.link.updated |
156164
| Text | Some text for the tool (edited) |
157165
And I press "Save changes"
166+
# Course tool placement should be enabled by default, so it should show in the Active placements column
167+
Then I should see "Mock placement" in the "Course Tool 1" "table_row"
158168
And I open the action menu in "Course Tool 1" "table_row"
159169
And I choose "Edit" in the open action menu
160-
Then "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
170+
And "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
161171
And the following fields in the "Placement: Mock placement" "fieldset" match these values:
162172
| Deep Linking Request URL | http://deep.link.updated |
163173
| Resource Linking Request URL | |
@@ -166,6 +176,7 @@ Feature: Configure placements for a tool
166176
# Deselect the placement and verify the related configurations are removed upon saving.
167177
And I click on "Mock placement" "autocomplete_selection"
168178
And I press "Save changes"
179+
And I should not see "Mock placement" in the "Course Tool 1" "table_row"
169180
And I open the action menu in "Course Tool 1" "table_row"
170181
And I choose "Edit" in the open action menu
171182
And "Mock placement" "autocomplete_selection" should not exist in the "Placement" "fieldset"
@@ -188,6 +199,7 @@ Feature: Configure placements for a tool
188199
# It should be hidden when nothing is selected in the beginning
189200
And the field "Placements" matches value ""
190201
And "Placement: Mock placement" "fieldset" should not be visible
202+
And I should not see "Default state" in the "Placement: Mock placement" "fieldset"
191203
And I should not see "Deep Linking Request URL" in the "Placement: Mock placement" "fieldset"
192204
And I should not see "Resource Linking Request URL" in the "Placement: Mock placement" "fieldset"
193205
And I should not see "Icon URL" in the "Placement: Mock placement" "fieldset"
@@ -197,13 +209,15 @@ Feature: Configure placements for a tool
197209
And I set the field "Placements" in the "Placement" "fieldset" to "Mock placement"
198210
Then "Mock placement" "autocomplete_selection" should exist in the "Placement" "fieldset"
199211
And "Placement: Mock placement" "fieldset" should be visible
212+
And I should see "Default state" in the "Placement: Mock placement" "fieldset"
200213
And I should see "Deep Linking Request URL" in the "Placement: Mock placement" "fieldset"
201214
And I should see "Resource Linking Request URL" in the "Placement: Mock placement" "fieldset"
202215
And I should see "Icon URL" in the "Placement: Mock placement" "fieldset"
203216
And I should see "Text" in the "Placement: Mock placement" "fieldset"
204217
# Removing the selected value will hide the fieldset
205218
And I click on "Mock placement" "autocomplete_selection"
206219
And "Placement: Mock placement" "fieldset" should not be visible
220+
And I should not see "Default state" in the "Placement: Mock placement" "fieldset"
207221
And I should not see "Deep Linking Request URL" in the "Placement: Mock placement" "fieldset"
208222
And I should not see "Resource Linking Request URL" in the "Placement: Mock placement" "fieldset"
209223
And I should not see "Icon URL" in the "Placement: Mock placement" "fieldset"

public/ltix/tests/helper_test.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ public static function load_placement_config_provider(): array {
14931493
[
14941494
'placementtypeid' => 2,
14951495
'configdata' => [
1496+
'default_usage' => 'enabled',
14961497
'resource_linking_url' => 'http://resourcelink.example.com',
14971498
'icon_url' => 'https://icon2.example.com',
14981499
'text' => 'Example text',
@@ -1501,6 +1502,7 @@ public static function load_placement_config_provider(): array {
15011502
[
15021503
'placementtypeid' => 3,
15031504
'configdata' => [
1505+
'default_usage' => 'disabled',
15041506
'deep_linking_url' => 'http://deeplink3.example.com',
15051507
'resource_linking_url' => 'http://resourcelink3.example.com',
15061508
'icon_url' => 'https://icon3.example.com',
@@ -1516,12 +1518,12 @@ public static function load_placement_config_provider(): array {
15161518
'resource_linking_url_placementconfig2' => 'http://resourcelink.example.com',
15171519
'icon_url_placementconfig2' => 'https://icon2.example.com',
15181520
'text_placementconfig2' => 'Example text',
1519-
'default_usage_placementconfig2' => 'enabled', // Set by create_tool_placements() generator function.
1521+
'default_usage_placementconfig2' => 'enabled',
15201522
'deep_linking_url_placementconfig3' => 'http://deeplink3.example.com',
15211523
'resource_linking_url_placementconfig3' => 'http://resourcelink3.example.com',
15221524
'icon_url_placementconfig3' => 'https://icon3.example.com',
15231525
'text_placementconfig3' => 'Example text 3',
1524-
'default_usage_placementconfig3' => 'enabled', // Set by create_tool_placements() generator function.
1526+
'default_usage_placementconfig3' => 'disabled',
15251527
],
15261528
],
15271529
'No tool placements' =>
@@ -1636,6 +1638,7 @@ public static function delete_tool_placements_by_type_provider(): array {
16361638
[
16371639
'placementtypeid' => 3,
16381640
'configdata' => [
1641+
'default_usage' => 'enabled',
16391642
'deep_linking_url' => 'http://deeplink3.example.com',
16401643
'resource_linking_url' => 'http://resourcelink3.example.com',
16411644
'icon_url' => 'https://icon3.example.com',
@@ -1666,6 +1669,7 @@ public static function delete_tool_placements_by_type_provider(): array {
16661669
[
16671670
'placementtypeid' => 3,
16681671
'configdata' => [
1672+
'default_usage' => 'disabled',
16691673
'deep_linking_url' => 'http://deeplink3.example.com',
16701674
'resource_linking_url' => 'http://resourcelink3.example.com',
16711675
'icon_url' => 'https://icon3.example.com',

0 commit comments

Comments
 (0)