mirror of
https://github.com/moodle/moodle.git
synced 2025-03-23 00:50:15 +01:00
MDL-61637 tool_dataprivacy: Context-based fetching
Blocks API do not provide methods to retrieve a list of blocks without filtering by UI-availability. We need to get course blocks based on their course context.
This commit is contained in:
parent
02c7769422
commit
c459409c1b
@ -312,29 +312,29 @@ class data_registry_page implements renderable, templatable {
|
||||
|
||||
$branches = [];
|
||||
|
||||
$blockinstances = \core_block_external::get_course_blocks($coursecontext->instanceid);
|
||||
if (empty($blockinstances['blocks'])) {
|
||||
return $branches;
|
||||
}
|
||||
$children = $coursecontext->get_child_contexts();
|
||||
foreach ($children as $childcontext) {
|
||||
|
||||
if ($childcontext->contextlevel !== CONTEXT_BLOCK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($blockinstances['blocks'] as $bi) {
|
||||
if (function_exists('block_instance_by_id')) {
|
||||
$blockinstance = block_instance_by_id($bi['instanceid']);
|
||||
$blockinstance = block_instance_by_id($childcontext->instanceid);
|
||||
} else {
|
||||
// TODO To be removed when MDL-61621 gets integrated.
|
||||
$blockinstance = $DB->get_record('block_instances', ['id' => $bi['instanceid']]);
|
||||
$blockinstance = $DB->get_record('block_instances', ['id' => $childcontext->instanceid]);
|
||||
$blockinstance = block_instance($blockinstance->blockname, $blockinstance);
|
||||
}
|
||||
$blockcontext = \context_block::instance($bi['instanceid']);
|
||||
$displayname = shorten_text(format_string($blockinstance->get_title(), true, ['context' => $blockcontext->id]));
|
||||
$displayname = shorten_text(format_string($blockinstance->get_title(), true, ['context' => $childcontext->id]));
|
||||
$branches[] = self::complete([
|
||||
'text' => $displayname,
|
||||
'contextid' => $blockcontext->id,
|
||||
'contextid' => $childcontext->id,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
return $branches;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user