diff --git a/.upgradenotes/MDL-87658-2026012211070898.yml b/.upgradenotes/MDL-87658-2026012211070898.yml new file mode 100644 index 00000000000..1b668277521 --- /dev/null +++ b/.upgradenotes/MDL-87658-2026012211070898.yml @@ -0,0 +1,9 @@ +issueNumber: MDL-87658 +notes: + aiplacement: + - message: >- + A new page-level property has been added to moodle_page to indicate + whether AI-related UI elements are preferred to be shown on a given + page. This value acts as an advisory hint only. It does not enforce the + visibility of AI-related UI elements globally. + type: improved diff --git a/public/ai/placement/courseassist/classes/output/assist_ui.php b/public/ai/placement/courseassist/classes/output/assist_ui.php index dc546434558..c52a3784dc1 100644 --- a/public/ai/placement/courseassist/classes/output/assist_ui.php +++ b/public/ai/placement/courseassist/classes/output/assist_ui.php @@ -100,7 +100,10 @@ class assist_ui { if ($PAGE->context->contextlevel != CONTEXT_MODULE) { return false; } - + // Check the advisory AI visibility hint on the page. + if (!$PAGE->get_ai_visibility_hint()) { + return false; + } // Check if the user has permission to use the AI service. return utils::is_course_assist_available(); } diff --git a/public/course/classes/route/controller/restricted_module.php b/public/course/classes/route/controller/restricted_module.php index eca9e97e66f..2cc841a0ee1 100644 --- a/public/course/classes/route/controller/restricted_module.php +++ b/public/course/classes/route/controller/restricted_module.php @@ -76,6 +76,7 @@ class restricted_module { $PAGE->set_heading($course->fullname); $PAGE->set_cm($cminfo); $PAGE->set_secondary_navigation(false); + $PAGE->set_ai_visibility_hint(false); $restrictedclass = $format->get_output_classname('content\\cm\\restricted'); $cmoutput = new $restrictedclass( diff --git a/public/lib/pagelib.php b/public/lib/pagelib.php index 8686fed9109..9245b1c902f 100644 --- a/public/lib/pagelib.php +++ b/public/lib/pagelib.php @@ -437,6 +437,16 @@ class moodle_page { */ protected bool $_showcourseindex = true; + /** + * Hint indicating whether AI-related UI elements should be shown on this page. + * + * This value is advisory only. Individual AI placements are responsible + * for deciding whether to respect this hint. + * + * @var bool + */ + protected bool $aivisibilityhint = true; + /** * Force the settings menu to be displayed on this page. This will only force the * settings menu on an activity / resource page that is being displayed on a theme that @@ -2488,4 +2498,32 @@ class moodle_page { public function get_show_course_index(): bool { return $this->_showcourseindex; } + + /** + * Sets a hint indicating whether AI-related UI elements should be shown + * on this page. + * + * This hint is not enforced globally and does not guarantee that AI UI + * elements will be hidden or shown. Each AI placement must explicitly + * check this value. + * + * @param bool $visible + * @return void + */ + public function set_ai_visibility_hint(bool $visible): void { + $this->aivisibilityhint = $visible; + } + + /** + * Returns a hint indicating whether AI-related UI elements should be shown + * on this page. + * + * This value does not enforce visibility. AI placements may choose whether + * and how to respect this hint. + * + * @return bool + */ + public function get_ai_visibility_hint(): bool { + return $this->aivisibilityhint; + } } diff --git a/public/lib/tests/moodle_page_test.php b/public/lib/tests/moodle_page_test.php index 60f13dc72ed..cc46922c771 100644 --- a/public/lib/tests/moodle_page_test.php +++ b/public/lib/tests/moodle_page_test.php @@ -888,6 +888,47 @@ final class moodle_page_test extends \advanced_testcase { $page->set_show_course_index(false); $this->assertFalse($page->get_show_course_index()); } + + /** + * Test that the AI visibility hint defaults to true. + */ + public function test_ai_visibility_hint_defaults_to_true(): void { + $page = new moodle_page(); + + $this->assertTrue( + $page->get_ai_visibility_hint(), + 'AI visibility hint should default to true.' + ); + } + + /** + * Test that the AI visibility hint can be disabled via the setter. + */ + public function test_ai_visibility_hint_can_be_set_to_false(): void { + $page = new moodle_page(); + + $page->set_ai_visibility_hint(false); + + $this->assertFalse( + $page->get_ai_visibility_hint(), + 'AI visibility hint should be false after being explicitly disabled.' + ); + } + + /** + * Test that the AI visibility hint can be re-enabled via the setter. + */ + public function test_ai_visibility_hint_can_be_set_to_true(): void { + $page = new moodle_page(); + + $page->set_ai_visibility_hint(false); + $page->set_ai_visibility_hint(true); + + $this->assertTrue( + $page->get_ai_visibility_hint(), + 'AI visibility hint should be true after being re-enabled.' + ); + } } /**