From ab1c3d2b598fba9727284e3010bbe23f0a4fd17f Mon Sep 17 00:00:00 2001 From: Daniel Poggenpohl Date: Mon, 10 Nov 2025 20:39:12 +0100 Subject: [PATCH] MDL-87017 blocks: Provide page context to page_type_list functions - The current context may be necessary when deleting a frontpage block displayed on every page with javascript disabled - The current context may be necessary when a frontpage block is displayed on every page and the question bank is viewed - Also handle a NULL currentcontext for question_page_type_list() correctly --- public/lib/blocklib.php | 4 ++-- public/lib/questionlib.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/lib/blocklib.php b/public/lib/blocklib.php index c19c7086e6e..b803163b317 100644 --- a/public/lib/blocklib.php +++ b/public/lib/blocklib.php @@ -1469,7 +1469,7 @@ class block_manager { if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) { $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block'); } else { - $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext); + $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context); $messagestring->pagetype = $block->instance->pagetypepattern; if (isset($pagetypes[$block->instance->pagetypepattern])) { $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern]; @@ -1686,7 +1686,7 @@ class block_manager { if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) { $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block'); } else { - $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext); + $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context); $messagestring->pagetype = $block->instance->pagetypepattern; if (isset($pagetypes[$block->instance->pagetypepattern])) { $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern]; diff --git a/public/lib/questionlib.php b/public/lib/questionlib.php index 09d721cbb65..dbbb23d31ea 100644 --- a/public/lib/questionlib.php +++ b/public/lib/questionlib.php @@ -1825,7 +1825,7 @@ function question_page_type_list($pagetype, $parentcontext, $currentcontext): ar 'question-export' => get_string('page-question-export', 'question'), 'question-import' => get_string('page-question-import', 'question') ]; - if ($currentcontext->contextlevel == CONTEXT_COURSE) { + if ($currentcontext && $currentcontext->contextlevel == CONTEXT_COURSE) { require_once($CFG->dirroot . '/course/lib.php'); return array_merge(course_page_type_list($pagetype, $parentcontext, $currentcontext), $types); } else {