MDL-81397 courseformat: define section editing capabilities.

This ensures consistency for current page instance, when rendering
content in response to fragment AJAX requests.
This commit is contained in:
Paul Holden 2024-05-21 14:13:26 +01:00
parent 1291869f90
commit 89fae608a6
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164

View File

@ -26,6 +26,7 @@ use coding_exception;
use core_course_renderer;
use core_courseformat\base as course_format;
use html_writer;
use moodle_page;
use renderable;
use section_info;
use stdClass;
@ -39,6 +40,23 @@ use stdClass;
*/
abstract class section_renderer extends core_course_renderer {
/**
* Constructor method, calls the parent constructor.
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
// Ensure capabilities for section editing controls match those defined in course/view.php to ensure that they work
// when called via an AJAX request.
if (course_get_format($page->course)->uses_sections()) {
$page->set_other_editing_capability('moodle/course:sectionvisibility');
$page->set_other_editing_capability('moodle/course:movesections');
}
}
/**
* Renders the provided widget and returns the HTML to display it.
*