From 35101a6a2c8ef97aa0301e7a2899fc1d9a3bf598 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 16 Sep 2020 12:32:22 +0200 Subject: [PATCH] MDL-68935 course: Return context data in get_content WS --- course/externallib.php | 2 ++ course/tests/externallib_test.php | 2 ++ course/upgrade.txt | 1 + 3 files changed, 5 insertions(+) diff --git a/course/externallib.php b/course/externallib.php index 5a896e7f2bf..5ac27f8feba 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -261,6 +261,7 @@ class core_course_external extends external_api { $module['id'] = $cm->id; $module['name'] = external_format_string($cm->name, $modcontext->id); $module['instance'] = $cm->instance; + $module['contextid'] = $modcontext->id; $module['modname'] = (string) $cm->modname; $module['modplural'] = (string) $cm->modplural; $module['modicon'] = $cm->get_icon_url()->out(false); @@ -442,6 +443,7 @@ class core_course_external extends external_api { 'url' => new external_value(PARAM_URL, 'activity url', VALUE_OPTIONAL), 'name' => new external_value(PARAM_RAW, 'activity module name'), 'instance' => new external_value(PARAM_INT, 'instance id', VALUE_OPTIONAL), + 'contextid' => new external_value(PARAM_INT, 'Activity context id.', VALUE_OPTIONAL), 'description' => new external_value(PARAM_RAW, 'activity description', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, 'is the module visible', VALUE_OPTIONAL), 'uservisible' => new external_value(PARAM_BOOL, 'Is the module visible for the user?', diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 57e61083be2..fcf938bc876 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -1015,6 +1015,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { array('noclean' => true, 'para' => false, 'filter' => false)); $this->assertEquals($formattedtext, $module['description']); $this->assertEquals($forumcm->instance, $module['instance']); + $this->assertEquals(context_module::instance($forumcm->id)->id, $module['contextid']); $this->assertContains('1 unread post', $module['afterlink']); $this->assertFalse($module['noviewlink']); $this->assertNotEmpty($module['description']); // Module showdescription is on. @@ -1025,6 +1026,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { array('noclean' => true, 'para' => false, 'filter' => false)); $this->assertEquals($formattedtext, $module['description']); $this->assertEquals($labelcm->instance, $module['instance']); + $this->assertEquals(context_module::instance($labelcm->id)->id, $module['contextid']); $this->assertTrue($module['noviewlink']); $this->assertNotEmpty($module['description']); // Label always prints the description. $testexecuted = $testexecuted + 1; diff --git a/course/upgrade.txt b/course/upgrade.txt index 4af9f853a00..e56837d5b02 100644 --- a/course/upgrade.txt +++ b/course/upgrade.txt @@ -4,6 +4,7 @@ information provided here is intended especially for developers. === 3.10 === * The function make_categories_options() has now been deprecated. Please use \core_course_category::make_categories_list() instead. +* External function core_course_external::get_course_contents now returns a new field contextid with the module context id. === 3.9 ===