Skip to content

Commit

Permalink
MDL-68935 course: Return context data in get_content WS
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Sep 16, 2020
1 parent d4d798e commit 35101a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions course/externallib.php
Expand Up @@ -261,6 +261,7 @@ public static function get_course_contents($courseid, $options = array()) {
$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);
Expand Down Expand Up @@ -442,6 +443,7 @@ public static function get_course_contents_returns() {
'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?',
Expand Down
2 changes: 2 additions & 0 deletions course/tests/externallib_test.php
Expand Up @@ -1015,6 +1015,7 @@ public function test_get_course_contents() {
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.
Expand All @@ -1025,6 +1026,7 @@ public function test_get_course_contents() {
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;
Expand Down
1 change: 1 addition & 0 deletions course/upgrade.txt
Expand Up @@ -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 ===

Expand Down

0 comments on commit 35101a6

Please sign in to comment.