From 6b3c3202272fc6c5aa3792bcf19e3f79aaeb9638 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Fri, 3 Jan 2025 07:42:52 +0100 Subject: [PATCH] MBS-9811: Add utility function to add a header to an course edit form --- classes/ai_manager_utils.php | 15 +++++++++++++++ lang/en/local_ai_manager.php | 1 + 2 files changed, 16 insertions(+) diff --git a/classes/ai_manager_utils.php b/classes/ai_manager_utils.php index a83f480..7a6c0cb 100644 --- a/classes/ai_manager_utils.php +++ b/classes/ai_manager_utils.php @@ -228,4 +228,19 @@ public static function find_closest_parent_course_context(context $context): ?co } return self::find_closest_parent_course_context($context->get_parent_context()); } + + /** + * Helper function to add a category to a (course edit) form. + * + * This can be called by other AI plugins using the {@see \core_course\hook\after_form_definition} hook to extend + * the course edit form. Calling this function will add an AI tools category below which the plugins can add their + * mform elements. This function will only add a category if there does not exist one yet. + * + * @param \MoodleQuickForm $mform the mform object to add the heading to + */ + public static function add_ai_tools_category_to_mform(\MoodleQuickForm $mform): void { + if (!$mform->elementExists('aitoolsheader')) { + $mform->addElement('header', 'aitoolsheader', get_string('aicourseeditheader', 'local_ai_manager')); + } + } } diff --git a/lang/en/local_ai_manager.php b/lang/en/local_ai_manager.php index c045640..149dcdc 100644 --- a/lang/en/local_ai_manager.php +++ b/lang/en/local_ai_manager.php @@ -36,6 +36,7 @@ $string['ai_manager:viewusernames'] = 'View non anonymized usernames in statistics'; $string['ai_manager:viewuserstatistics'] = 'View statistics of single users'; $string['aiadministrationlink'] = 'AI tools administration'; +$string['aicourseeditheader'] = 'AI functionalities'; $string['aiinfotitle'] = 'AI tools in your tenant'; $string['aiisbeingused'] = 'You are using an AI tool. The entered data will be sent to an external AI tool.'; $string['aitool'] = 'AI tool';