From 2a708f985aa2b12c71a919fe5c36a3ceb3442ebf Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Thu, 4 Jan 2024 18:02:51 +0100 Subject: [PATCH] MDL-80461 courseformat: Use choicedropdown for the format setting In MDL-79985 a new form element was created to display a new generic dropdown with extra information like a description or an icon on each option. This commits replaces the select for the course format form element in the Course settings page with this new component. --- .../tool/uploadcourse/classes/step2_form.php | 24 ++++++++++-- course/edit_form.php | 37 ++++++++++++++----- .../lang/en/format_singleactivity.php | 1 + .../format/social/lang/en/format_social.php | 1 + .../format/topics/lang/en/format_topics.php | 1 + course/format/upgrade.txt | 2 + course/format/weeks/lang/en/format_weeks.php | 1 + lang/en/deprecated.txt | 1 + lang/en/moodle.php | 12 +++--- 9 files changed, 60 insertions(+), 20 deletions(-) diff --git a/admin/tool/uploadcourse/classes/step2_form.php b/admin/tool/uploadcourse/classes/step2_form.php index ffd6ba06f79..033c2aba273 100644 --- a/admin/tool/uploadcourse/classes/step2_form.php +++ b/admin/tool/uploadcourse/classes/step2_form.php @@ -120,12 +120,28 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form { $mform->addHelpButton('defaults[enddate]', 'enddate'); $courseformats = get_sorted_course_formats(true); - $formcourseformats = array(); + $formcourseformats = new core\output\choicelist(); + $formcourseformats->set_allow_empty(false); foreach ($courseformats as $courseformat) { - $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); + $definition = []; + $component = "format_$courseformat"; + if (get_string_manager()->string_exists('plugin_description', $component)) { + $definition['description'] = get_string('plugin_description', $component); + } + $formcourseformats->add_option( + $courseformat, + get_string('pluginname', "format_$courseformat"), + [ + 'description' => $definition, + ], + ); } - $mform->addElement('select', 'defaults[format]', get_string('format'), $formcourseformats); - $mform->addHelpButton('defaults[format]', 'format'); + $mform->addElement( + 'choicedropdown', + 'defaults[format]', + get_string('format'), + $formcourseformats, + ); $mform->setDefault('defaults[format]', $courseconfig->format); if (!empty($CFG->allowcoursethemes)) { diff --git a/course/edit_form.php b/course/edit_form.php index c5f2b44611e..3b67acb6f50 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -221,23 +221,40 @@ class course_edit_form extends moodleform { $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin')); $courseformats = get_sorted_course_formats(true); - $formcourseformats = array(); + $formcourseformats = new core\output\choicelist(); + $formcourseformats->set_allow_empty(false); foreach ($courseformats as $courseformat) { - $formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat"); + $definition = []; + $component = "format_$courseformat"; + if (get_string_manager()->string_exists('plugin_description', $component)) { + $definition['description'] = get_string('plugin_description', $component); + } + $formcourseformats->add_option( + $courseformat, + get_string('pluginname', "format_$courseformat"), + [ + 'description' => $definition, + ], + ); } if (isset($course->format)) { - $course->format = course_get_format($course)->get_format(); // replace with default if not found + $course->format = course_get_format($course)->get_format(); // Replace with default if not found. if (!in_array($course->format, $courseformats)) { - // this format is disabled. Still display it in the dropdown - $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', - get_string('pluginname', 'format_'.$course->format)); + // This format is disabled. Still display it in the dropdown. + $formcourseformats->add_option( + $course->format, + get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_'.$course->format)), + ); } } - $mform->addElement('select', 'format', get_string('format'), $formcourseformats, [ - 'data-formatchooser-field' => 'selector', - ]); - $mform->addHelpButton('format', 'format'); + $mform->addElement( + 'choicedropdown', + 'format', + get_string('format'), + $formcourseformats, + ['data-formatchooser-field' => 'selector'], + ); $mform->setDefault('format', $courseconfig->format); // Button to update format-specific options on format change (will be hidden by JavaScript). diff --git a/course/format/singleactivity/lang/en/format_singleactivity.php b/course/format/singleactivity/lang/en/format_singleactivity.php index 5ccb3e2182f..ad2ae685b7b 100644 --- a/course/format/singleactivity/lang/en/format_singleactivity.php +++ b/course/format/singleactivity/lang/en/format_singleactivity.php @@ -30,6 +30,7 @@ $string['erroractivitytype'] = 'Type of activity is not set up in Course setting $string['orphaned'] = 'Orphaned'; $string['orphanedwarning'] = 'These activities are unreachable by users!'; $string['pluginname'] = 'Single activity'; +$string['plugin_description'] = 'The course contains only one activity or resource.'; $string['sectionname'] = ''; $string['warningchangeformat'] = 'When changing the existing course format to "Single activity" make sure that you removed all extra activities from the course including "Announcements". Note that sections structure may be modified.'; $string['privacy:metadata'] = 'The Single activity format plugin does not store any personal data.'; diff --git a/course/format/social/lang/en/format_social.php b/course/format/social/lang/en/format_social.php index 151ea6b7a87..fab01047d0a 100644 --- a/course/format/social/lang/en/format_social.php +++ b/course/format/social/lang/en/format_social.php @@ -26,5 +26,6 @@ $string['numberdiscussions'] = 'Number of discussions'; $string['numberdiscussions_help'] = 'This setting specifies how many discussions should be displayed.'; $string['pluginname'] = 'Social'; +$string['plugin_description'] = 'The course is centred around a main forum on the course page. Additional activities and resources can be added using the Social activities block.'; $string['sectionname'] = 'section'; $string['privacy:metadata'] = 'The Social format plugin does not store any personal data.'; diff --git a/course/format/topics/lang/en/format_topics.php b/course/format/topics/lang/en/format_topics.php index 1ee0f5a7ce1..3cc3a62d4da 100644 --- a/course/format/topics/lang/en/format_topics.php +++ b/course/format/topics/lang/en/format_topics.php @@ -27,6 +27,7 @@ $string['hidefromothers'] = 'Hide'; $string['page-course-view-topics'] = 'Any course main page in custom sections format'; $string['page-course-view-topics-x'] = 'Any course page in custom sections format'; $string['pluginname'] = 'Custom sections'; +$string['plugin_description'] = 'The course is divided into customisable sections.'; $string['privacy:metadata'] = 'The Custom sections format plugin does not store any personal data.'; $string['indentation'] = 'Allow indentation on course page'; $string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.'; diff --git a/course/format/upgrade.txt b/course/format/upgrade.txt index 121afc8c2d3..e9042ea86d2 100644 --- a/course/format/upgrade.txt +++ b/course/format/upgrade.txt @@ -47,6 +47,8 @@ always linked because a new page, section.php, has been created to display any s - course/format/topics/renderer.php - course/format/weeks/renderer.php * New core_courseformat\sectiondelegate class. The class can be extended by plugins to take control of a course section. +* The course format setting has been updated to use a choice dropdown form element instead of a select element. Third-party +plugins can now include the string 'plugin_description' to provide a description of the course format. === 4.3 === * New core_courseformat\output\activitybadge class that can be extended by any module to display content near the activity name. diff --git a/course/format/weeks/lang/en/format_weeks.php b/course/format/weeks/lang/en/format_weeks.php index 074f8b76860..58f009fafe3 100644 --- a/course/format/weeks/lang/en/format_weeks.php +++ b/course/format/weeks/lang/en/format_weeks.php @@ -30,6 +30,7 @@ $string['hidefromothers'] = 'Hide'; $string['page-course-view-weeks'] = 'Any course main page in weekly sections format'; $string['page-course-view-weeks-x'] = 'Any course page in weekly sections format'; $string['pluginname'] = 'Weekly sections'; +$string['plugin_description'] = 'The course is divided into sections corresponding to each week, beginning from the course start date.'; $string['privacy:metadata'] = 'The Weekly sections format plugin does not store any personal data.'; $string['indentation'] = 'Allow indentation on course page'; $string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.'; diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index d78d401ef99..96147edbc26 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -132,3 +132,4 @@ topicshow,core topichide,core summary_help,core editsummary,core +format_help,core diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 9e86d6ca94f..a0f2c13b3f8 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -935,12 +935,6 @@ $string['forgotten'] = 'Forgotten your username or password?'; $string['forgottenduplicate'] = 'The email address is shared by several accounts, please enter username instead'; $string['forgotteninvalidurl'] = 'Invalid password reset URL'; $string['format'] = 'Format'; -$string['format_help'] = 'The course format determines the layout of the course page. - -* Single activity - The course contains only one activity or resource. -* Social - A forum is displayed on the course page. -* Custom sections - The course is divided into customisable sections. -* Weekly sections - The course is divided into sections corresponding to each week, beginning from the course start date.'; $string['formathtml'] = 'HTML format'; $string['formatmarkdown'] = 'Markdown format'; $string['formatplain'] = 'Plain text format'; @@ -2501,3 +2495,9 @@ $string['topicshow'] = 'Show this topic to {$a}'; $string['topichide'] = 'Hide this topic from {$a}'; $string['summary_help'] = 'The idea of a summary is a short text to prepare students for the activities within the topic or week. The text is shown on the course page under the section name.'; $string['editsummary'] = 'Edit summary'; +$string['format_help'] = 'The course format determines the layout of the course page. + +* Single activity - The course contains only one activity or resource. +* Social - The course is centred around a main forum on the course page. Additional activities and resources can be added using the Social activities block. +* Custom sections - The course is divided into customisable sections. +* Weekly sections - The course is divided into sections corresponding to each week, beginning from the course start date.';