From 9f544e70aecb30fc52e6591cba36ef0ea054a5d3 Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Wed, 9 Oct 2024 13:43:33 +0200 Subject: [PATCH] MDL-82351 format_social: migrate to reactive course editor The commit adds all the necessary methods to allow social format to use the course editor. The code is similar to the one used in the frontpage format. The commit does not include the migration of the social_activities blocks. --- .../format/social/lang/en/format_social.php | 5 ++- course/format/social/lib.php | 40 ++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/course/format/social/lang/en/format_social.php b/course/format/social/lang/en/format_social.php index fab01047d0a32..0a653dfbe42cc 100644 --- a/course/format/social/lang/en/format_social.php +++ b/course/format/social/lang/en/format_social.php @@ -23,9 +23,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['hidefromothers'] = 'Hide'; $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.'; +$string['sectionname'] = 'section'; +$string['socialactivities'] = 'Social activities'; +$string['showfromothers'] = 'Show'; diff --git a/course/format/social/lib.php b/course/format/social/lib.php index 79c21bb0a98b0..e1b5b82412a13 100644 --- a/course/format/social/lib.php +++ b/course/format/social/lib.php @@ -129,18 +129,40 @@ public function get_config_for_external() { return $this->get_format_options(); } - /** - * Returns the information about the ajax support in the given source format. - * - * The returned object's property (boolean)capable indicates that - * the course format supports Moodle course ajax features. - * - * @return stdClass - */ public function supports_ajax() { + // All home page is rendered in the backend, we only need an ajax editor components in edit mode. + // This will also prevent redirectng to the login page when a guest tries to access the site, + // and will make the home page loading faster. $ajaxsupport = new stdClass(); - $ajaxsupport->capable = true; + $ajaxsupport->capable = $this->show_editor(); return $ajaxsupport; } + public function supports_components() { + return true; + } + + public function uses_sections() { + return true; + } + + public function get_section_name($section) { + return get_string('socialactivities', 'format_social'); + } + + /** + * Social format uses only section 0. + * + * @return int + */ + public function get_sectionnum(): int { + return 0; + } + + + #[\Override] + public function get_max_sections() { + // Social ony uses one section. + return 1; + } }