MDL-65969 course: Indicate when the module is not linking to a new page

This commit is contained in:
Juan Leyva 2019-08-15 20:33:08 +01:00
parent 8e9e9a5f7e
commit 62b40d2743
2 changed files with 10 additions and 1 deletions

View File

@ -269,6 +269,7 @@ class core_course_external extends external_api {
$module['afterlink'] = $cm->afterlink;
$module['customdata'] = json_encode($cm->customdata);
$module['completion'] = $cm->completion;
$module['noviewlink'] = plugin_supports('mod', $cm->modname, FEATURE_NO_VIEW_LINK, false);
// Check module completion.
$completion = $completioninfo->is_enabled($cm);
@ -282,7 +283,7 @@ class core_course_external extends external_api {
);
}
if (!empty($cm->showdescription) or $cm->modname == 'label') {
if (!empty($cm->showdescription) or $module['noviewlink']) {
// We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML.
$options = array('noclean' => true);
list($module['description'], $descriptionformat) = external_format_text($cm->content,
@ -458,6 +459,8 @@ class core_course_external extends external_api {
'afterlink' => new external_value(PARAM_RAW, 'After link info to be displayed.',
VALUE_OPTIONAL),
'customdata' => new external_value(PARAM_RAW, 'Custom data (JSON encoded).', VALUE_OPTIONAL),
'noviewlink' => new external_value(PARAM_BOOL, 'Whether the module does link to
a new page.', VALUE_OPTIONAL),
'completion' => new external_value(PARAM_INT, 'Type of completion tracking:
0 means none, 1 manual, 2 automatic.', VALUE_OPTIONAL),
'completiondata' => new external_single_structure(

View File

@ -942,6 +942,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals($formattedtext, $module['description']);
$this->assertEquals($forumcm->instance, $module['instance']);
$this->assertContains('1 unread post', $module['afterlink']);
$this->assertFalse($module['noviewlink']);
$this->assertNotEmpty($module['description']); // Module showdescription is on.
$testexecuted = $testexecuted + 2;
} else if ($module['id'] == $labelcm->id and $module['modname'] == 'label') {
$cm = $modinfo->cms[$labelcm->id];
@ -949,9 +951,13 @@ 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->assertTrue($module['noviewlink']);
$this->assertNotEmpty($module['description']); // Label always prints the description.
$testexecuted = $testexecuted + 1;
} else if ($module['id'] == $datacm->id and $module['modname'] == 'data') {
$this->assertContains('customcompletionrules', $module['customdata']);
$this->assertFalse($module['noviewlink']);
$this->assertArrayNotHasKey('description', $module);
$testexecuted = $testexecuted + 1;
}
}