Commit f7b0960d authored by Sara Arjona's avatar Sara Arjona
Browse files

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.
parent 411150a4
......@@ -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;
}
/**
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 {
}
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment