From 85a5070be12d997adf9b1db5227658d85f01256b Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 19 Oct 2023 16:43:03 +0200 Subject: [PATCH] MDL-79786 mod: Include purpose for setting icons colours --- course/externallib.php | 2 ++ course/tests/externallib_test.php | 33 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/course/externallib.php b/course/externallib.php index 55a7f49e4fd..47aa3d4dcd1 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -266,6 +266,7 @@ class core_course_external extends external_api { $module['modname'] = (string) $cm->modname; $module['modplural'] = (string) $cm->modplural; $module['modicon'] = $cm->get_icon_url()->out(false); + $module['purpose'] = plugin_supports('mod', $cm->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER); $module['indent'] = $cm->indent; $module['onclick'] = $cm->onclick; $module['afterlink'] = $cm->afterlink; @@ -461,6 +462,7 @@ class core_course_external extends external_api { VALUE_OPTIONAL), 'modicon' => new external_value(PARAM_URL, 'activity icon url'), 'modname' => new external_value(PARAM_PLUGIN, 'activity module type'), + 'purpose' => new external_value(PARAM_ALPHA, 'the module purpose'), 'modplural' => new external_value(PARAM_TEXT, 'activity module plural name'), 'availability' => new external_value(PARAM_RAW, 'module availability settings', VALUE_OPTIONAL), 'indent' => new external_value(PARAM_INT, 'number of identation in the site'), diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 04f48008bbc..e041c9b49bc 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -1179,7 +1179,14 @@ class externallib_test extends externallib_advanced_testcase { $this->assertEmpty($module['afterlink']); $this->assertEquals('1 unread post', $module['activitybadge']['badgecontent']); $this->assertEquals('badge-dark', $module['activitybadge']['badgestyle']); - + $this->assertEquals( + plugin_supports( + 'mod', + 'forum', + FEATURE_MOD_PURPOSE, + MOD_PURPOSE_OTHER + ), $module['purpose'] + ); $testexecuted = $testexecuted + 2; } else if ($module['id'] == $labelcm->id and $module['modname'] == 'label') { $cm = $modinfo->cms[$labelcm->id]; @@ -1191,17 +1198,41 @@ class externallib_test extends externallib_advanced_testcase { $this->assertTrue($module['noviewlink']); $this->assertNotEmpty($module['description']); // Label always prints the description. $testexecuted = $testexecuted + 1; + $this->assertEquals( + plugin_supports( + 'mod', + 'label', + FEATURE_MOD_PURPOSE, + MOD_PURPOSE_OTHER + ), $module['purpose'] + ); } else if ($module['id'] == $datacm->id and $module['modname'] == 'data') { $this->assertStringContainsString('customcompletionrules', $module['customdata']); $this->assertFalse($module['noviewlink']); $this->assertArrayNotHasKey('description', $module); $testexecuted = $testexecuted + 1; + $this->assertEquals( + plugin_supports( + 'mod', + 'data', + FEATURE_MOD_PURPOSE, + MOD_PURPOSE_OTHER + ), $module['purpose'] + ); } else if ($module['instance'] == $resource->id && $module['modname'] == 'resource') { // Resources have both, afterlink for the size and the update date and activitybadge for the file type. $this->assertStringContainsString('32 bytes', $module['afterlink']); $this->assertEquals('TXT', $module['activitybadge']['badgecontent']); $this->assertEquals('badge-none', $module['activitybadge']['badgestyle']); $testexecuted = $testexecuted + 1; + $this->assertEquals( + plugin_supports( + 'mod', + 'resource', + FEATURE_MOD_PURPOSE, + MOD_PURPOSE_OTHER + ), $module['purpose'] + ); } } foreach ($sections[2]['modules'] as $module) {