From f7b0960d188aad187d9dae763bedcafd0deada63 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Thu, 25 Mar 2021 18:04:57 +0100 Subject: [PATCH] MDL-71135 course: add legacy_format_renderer support Until Moodle 4.0, renderer.php file was optional (although highly recommended) for course formats. From Moodle 4.0 onwards, renderer is required to support the new course editor implementation. The legacy_format_renderer class has been created for backward compatibility, to avoid some errors with course formats (such as social) without the renderer file. Apart from that, course_format->get_renderer() method has been reviewed to use this legacy_format_renderer when no renderer.php file is found. --- course/classes/course_format.php | 15 +++++++- .../course_format/legacy_format_renderer.php | 38 +++++++++++++++++++ course/upgrade.txt | 3 ++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 course/classes/output/course_format/legacy_format_renderer.php diff --git a/course/classes/course_format.php b/course/classes/course_format.php index f55b3c97163..1549e41e07d 100644 --- a/course/classes/course_format.php +++ b/course/classes/course_format.php @@ -38,6 +38,7 @@ use lang_string; use completion_info; use external_api; use stdClass; +use core_course\output\course_format\legacy_format_renderer; /** * Base class for course formats @@ -1055,7 +1056,19 @@ abstract class course_format { * @return renderer_base */ public function get_renderer(moodle_page $page) { - return $page->get_renderer('format_'. $this->get_format()); + try { + $renderer = $page->get_renderer('format_'. $this->get_format()); + } catch (moodle_exception $e) { + $formatname = $this->get_format(); + $expectedrenderername = 'format_'. $this->get_format() . '\output\renderer'; + debugging( + "The '{$formatname}' course format does not define the {$expectedrenderername} renderer class. This is required since Moodle 4.0.", + DEBUG_DEVELOPER + ); + $renderer = new legacy_format_renderer($page, null); + } + + return $renderer; } /** diff --git a/course/classes/output/course_format/legacy_format_renderer.php b/course/classes/output/course_format/legacy_format_renderer.php new file mode 100644 index 00000000000..9530becb407 --- /dev/null +++ b/course/classes/output/course_format/legacy_format_renderer.php @@ -0,0 +1,38 @@ +. + +/** + * Legacy course format renderer. + * + * Since Moodle 4.0, renderer.php file was optional (although highly recommended) for course formats. From Moodle 4.0 onwards, + * renderer is required to support the new course editor implementation. + * This legacy class has been created for backward compatibility, to avoid some errors with course formats (such as social) + * without this renderer.php file. + * + * @package core_course + * @copyright 2021 Sara Arjona (sara@moodle.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace core_course\output\course_format; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot.'/course/format/renderer.php'); + +class legacy_format_renderer extends \format_section_renderer_base { + +} diff --git a/course/upgrade.txt b/course/upgrade.txt index 3f0590c1765..e59c36ae6bd 100644 --- a/course/upgrade.txt +++ b/course/upgrade.txt @@ -43,6 +43,9 @@ renderer and course format renderer: - start_section_list (integrated in output\course_format) - end_section_list (integrated in output\course_format) - page_title (moved to output\course_format) +* Course formats should have a renderer (until now it was only highly recommended but not mandatory). For backwards +compatibility (to not break third-party plugins without it), legacy_format_renderer has been created and will be used when +course formats don't have their own renderer. === 3.11 === * A new callback xxx_coursemodule_definition_after_data that allows plugins to extend activity forms after the data is set.