MDL-62554 tool_dataprivacy: Fix display of activity options
authorJun Pataleta <jun@moodle.com>
Tue, 4 Sep 2018 08:52:08 +0000 (16:52 +0800)
committerJun Pataleta <jun@moodle.com>
Mon, 10 Sep 2018 04:16:20 +0000 (12:16 +0800)
admin/tool/dataprivacy/classes/external.php
admin/tool/dataprivacy/tests/external_test.php

index 2b6ee23..ff8ce80 100644 (file)
@@ -1367,12 +1367,16 @@ class external extends external_api {
         $pluginmanager = \core_plugin_manager::instance();
         $modplugins = $pluginmanager->get_plugins_of_type('mod');
         $modoptions = [];
+
+        // Get the module-level defaults. data_registry::get_defaults falls back to this when there are no activity defaults.
+        list($levelpurpose, $levelcategory) = data_registry::get_defaults(CONTEXT_MODULE);
         foreach ($modplugins as $plugin) {
             // Check if we have default purpose and category for this module if we want don't want to fetch everything.
             if ($nodefaults) {
                 list($purpose, $category) = data_registry::get_defaults(CONTEXT_MODULE, $plugin->name);
-                if ($purpose !== false || $category !== false) {
-                    // If so, skip it.
+                // Compare this with the module-level defaults.
+                if ($purpose !== $levelpurpose || $category !== $levelcategory) {
+                    // If the defaults for this activity has been already set, there's no need to add this in the list of options.
                     continue;
                 }
             }
index d7cded9..5448d5f 100644 (file)
@@ -544,6 +544,9 @@ class tool_dataprivacy_external_testcase extends externallib_advanced_testcase {
         $return = (object) external_api::clean_returnvalue(external::get_activity_options_returns(), $result);
         $options = $return->options;
 
+        // Make sure the options list is not empty.
+        $this->assertNotEmpty($options);
+
         $pluginwithdefaults = [
             'name' => 'assign',
             'displayname' => get_string('pluginname', 'assign')