diff --git a/admin/tool/dataprivacy/classes/data_registry.php b/admin/tool/dataprivacy/classes/data_registry.php index d85035cf4e6..549f0bfea5b 100644 --- a/admin/tool/dataprivacy/classes/data_registry.php +++ b/admin/tool/dataprivacy/classes/data_registry.php @@ -28,10 +28,7 @@ namespace tool_dataprivacy; use coding_exception; -use tool_dataprivacy\purpose; -use tool_dataprivacy\category; -use tool_dataprivacy\contextlevel; -use tool_dataprivacy\context_instance; +use core\persistent; defined('MOODLE_INTERNAL') || die(); @@ -95,6 +92,19 @@ class data_registry { $purposeid = get_config('tool_dataprivacy', $purposevar); $categoryid = get_config('tool_dataprivacy', $categoryvar); + if (!empty($pluginname)) { + list($purposevar, $categoryvar) = self::var_names_from_context($classname); + // If the plugin-level doesn't have a default purpose set, try the context level. + if ($purposeid === false) { + $purposeid = get_config('tool_dataprivacy', $purposevar); + } + + // If the plugin-level doesn't have a default category set, try the context level. + if ($categoryid === false) { + $categoryid = get_config('tool_dataprivacy', $categoryvar); + } + } + if (empty($purposeid)) { $purposeid = false; } @@ -209,9 +219,15 @@ class data_registry { // Use the context level value as we don't allow people to set specific instances values. return self::get_effective_contextlevel_value($context->contextlevel, $element); } else { + // Check if we need to pass the plugin name of an activity. + $forplugin = ''; + if ($context->contextlevel == CONTEXT_MODULE) { + list($course, $cm) = get_course_and_cm_from_cmid($context->instanceid); + $forplugin = $cm->modname; + } // Use the default context level value. list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category( - $context->contextlevel + $context->contextlevel, false, false, $forplugin ); return self::get_element_instance($element, $$fieldname); } @@ -295,14 +311,15 @@ class data_registry { * Returns the effective default purpose and category for a context level. * * @param int $contextlevel - * @param int $forcedpurposevalue Use this value as if this was this context level purpose. - * @param int $forcedcategoryvalue Use this value as if this was this context level category. + * @param bool $forcedpurposevalue Use this value as if this was this context level purpose. + * @param bool $forcedcategoryvalue Use this value as if this was this context level category. + * @param string $activity The plugin name of the activity. * @return int[] */ public static function get_effective_default_contextlevel_purpose_and_category($contextlevel, $forcedpurposevalue = false, - $forcedcategoryvalue = false) { + $forcedcategoryvalue = false, $activity = '') { - list($purposeid, $categoryid) = self::get_defaults($contextlevel); + list($purposeid, $categoryid) = self::get_defaults($contextlevel, $activity); // Honour forced values. if ($forcedpurposevalue) {