From c87017e3678cc80e330d6796c26c5a7bfe1a08a9 Mon Sep 17 00:00:00 2001 From: James C <5689414+james-cnz@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:46:02 +1300 Subject: [PATCH] Improve the Hidden sections setting (MDL-79918) --- lib.php | 33 ++++++++++++++++++++++++++++++++- settings.php | 31 +++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/lib.php b/lib.php index a099c7d..2654199 100644 --- a/lib.php +++ b/lib.php @@ -544,6 +544,7 @@ public function get_default_blocks() { * @return array of options */ public function course_format_options($foreditform = false) { + global $CFG; static $courseformatoptions = false; if ($courseformatoptions === false) { $courseconfig = get_config('format_onetopic'); @@ -584,8 +585,32 @@ public function course_format_options($foreditform = false) { } if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) { + if ($CFG->version >= 2025082900) { + $hiddensectionslist = new core\output\choicelist(); + $hiddensectionslist->set_allow_empty(false); + $hiddensectionslist->add_option( + self::HIDDENSENTIONS_INVISIBLE, + new lang_string('hiddensectionsinvisible'), + [ + 'description' => new lang_string('hiddensectionsinvisible_description'), + ], + ); + $hiddensectionslist->add_option( + self::HIDDENSENTIONS_COLLAPSED, + new lang_string('hiddensectionscollapsed'), + [ + 'description' => new lang_string('hiddensectionscollapsed_description'), + ], + ); + $hiddensectionslist->add_option( + self::HIDDENSENTIONS_HELP, + new lang_string('hiddensectionshelp', 'format_onetopic'), + [], + ); + } + $courseformatoptionsedit = [ - 'hiddensections' => [ + 'hiddensections' => ($CFG->version < 2025082900) ? [ 'label' => new lang_string('hiddensections'), 'help' => 'hiddensections', 'help_component' => 'moodle', @@ -597,6 +622,12 @@ public function course_format_options($foreditform = false) { self::HIDDENSENTIONS_HELP => new lang_string('hiddensectionshelp', 'format_onetopic'), ], ], + ] : [ + 'label' => new lang_string('hiddensections'), + 'element_type' => 'choicedropdown', + 'element_attributes' => [ + $hiddensectionslist, + ], ], 'hidetabsbar' => [ 'label' => get_string('hidetabsbar', 'format_onetopic'), diff --git a/settings.php b/settings.php index 226b29f..eec2f37 100644 --- a/settings.php +++ b/settings.php @@ -62,16 +62,27 @@ $settings->add($setting); // Default hidden sections visibility. - $options = [ - \format_onetopic::HIDDENSENTIONS_COLLAPSED => new lang_string('hiddensectionscollapsed'), - \format_onetopic::HIDDENSENTIONS_INVISIBLE => new lang_string('hiddensectionsinvisible'), - \format_onetopic::HIDDENSENTIONS_HELP => new lang_string('hiddensectionshelp', 'format_onetopic'), - ]; - $settings->add(new admin_setting_configselect('format_onetopic/defaulthiddensections', - get_string('hiddensections'), - get_string('hiddensections_help'), - \format_onetopic::HIDDENSENTIONS_HELP, - $options) + if ($CFG->version < 2025082900) { + $options = [ + \format_onetopic::HIDDENSENTIONS_COLLAPSED => new lang_string('hiddensectionscollapsed'), + \format_onetopic::HIDDENSENTIONS_INVISIBLE => new lang_string('hiddensectionsinvisible'), + \format_onetopic::HIDDENSENTIONS_HELP => new lang_string('hiddensectionshelp', 'format_onetopic'), + ]; + } else { + $options = [ + \format_onetopic::HIDDENSENTIONS_INVISIBLE => new lang_string('hiddensectionsinvisible'), + \format_onetopic::HIDDENSENTIONS_COLLAPSED => new lang_string('hiddensectionscollapsed'), + \format_onetopic::HIDDENSENTIONS_HELP => new lang_string('hiddensectionshelp', 'format_onetopic'), + ]; + } + $settings->add( + new admin_setting_configselect( + 'format_onetopic/defaulthiddensections', + get_string('hiddensections'), + ($CFG->version < 2025082900) ? get_string('hiddensections_help') : null, + \format_onetopic::HIDDENSENTIONS_HELP, + $options + ) ); // Default course display.